PouchDB - Miscellaneous

在本章中,我们将讨论PouchDB中压缩和检索批量数据等概念.

压缩

您可以减少通过使用 compact()方法删除未使用的数据来确定数据库的大小.您可以使用此方法压缩本地数据库以及远程数据库.

以下是演示在PouchDB中使用 compact()方法的示例.

//Requiring the package
var PouchDB = require('PouchDB');

//Creating the database object
var db = new PouchDB('sample_database');

db.compact(function (err, result) {
   if (err) {
      return console.log(err);
   } else {
      console.log(result);
   }
});

BulkGet方法

您可以使用 bulkGet()方法.对于此方法,您需要传递一组id和_rev.

以下示例演示了在PouchDB中 bulkGet()方法的用法.

//Requiring the package
var PouchDB = require('PouchDB');

//Creating the database object
var db = new PouchDB('my_database');

//Preparing documents
//Inserting Document
db.bulkGet({docs: [
   { id: "001", rev: "1-5dc593eda0e215c806677df1d12d5c47"},
   { id: "002", rev: "1-2bfad8a9e66d2679b99c0cab24bd9cc8"},
   { id: "003", rev: "1-7cff4a5da1f97b077a909ff67bd5b047"} ]}, function(err, result) {
   if (err) {
      return console.log(err);
   } else {
      console.log(result);
   }
});