我需要从 PouchDB 数据库中获取所有文档。谁能告诉我如何从回调函数中获取“文档”?我想将它作为响应对象返回,并在控制台输出中获取它。
var db = new pouchdb('meetups');
db.allDocs({
include_docs: true,
attachments: true
}).then(function (err,res) {
console.log("Result..."+res);
res.json({'users':res});
}).catch(function (err) {
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
我认为你想要的是以下内容:
var db = new pouchdb("meetups");
db.allDocs({
include_docs: true,
attachments: true
}).then(function (result) {
console.log(result);
res.json({"users": result.rows});
}).catch(function (err) {
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
如果出现错误,它将由您的catch回调处理,因此您的回调中只有一个参数 ( result) then。该result变量将包括一些关于结果的元数据(例如total_rows)以及一个rows属性,该属性将是数据库中所有文档的数组。
| 归档时间: |
|
| 查看次数: |
6852 次 |
| 最近记录: |