- PouchDB 教程
- PouchDB - 首页
- PouchDB - 概览
- PouchDB - 环境
- PouchDB - 创建数据库
- PouchDB - 数据库信息
- PouchDB - 删除数据库
- PouchDB - 创建文档
- PouchDB - 读取文档
- PouchDB - 更新文档
- PouchDB - 删除文档
- PouchDB - 创建批处理
- PouchDB - 获取批处理
- PouchDB - 更新批处理
- PouchDB - 删除批处理
- PouchDB - 添加附件
- PouchDB - 检索附件
- PouchDB - 删除附件
- PouchDB - 复制
- PouchDB - 同步
- PouchDB - 其他数据
- PouchDB 实用资源
- PouchDB - 快速指南
- PouchDB - 实用资源
- PouchDB - 讨论
PouchDB - 其他数据
本篇中,我们将讨论一些概念,例如,数据压缩以及从 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);
}
});
广告