javascript - 如何使用 node.js 获取 pouchdb 文档的所有 id
问题描述
我想知道如何使用 node.js 从 pouchdb 获取某个数据库的所有 id 这是我的尝试,但你可以猜到它没有工作,特别是我需要将所有 id 放入一个数组数字,只有 id 没有别的。我是 javascript 和数据库的初学者
var PouchDB = require('PouchDB');
var db = new PouchDB('mes_iab_db');
db.allDocs({
include_docs: true,
attachments: true
}).then(function (result) {
console.log(result)
var new1 = JSON.stringify(result.rows);
console.log(new1);
new1.filter(id=>{id=_id;})
}).catch(function (err) {
console.log(err);
});
解决方案
尝试这样的事情
db.allDocs({
include_docs: true,
attachments: true,
})
.then(function (result) {
if (result.rows && result.rows.length) {
return result.rows.map(({ doc }) => doc._id);
}
return [];
})
.then(console.log)
.catch(function (err) {
console.log(err);
});
推荐阅读
- node.js - npm install myPackage -g,错误:找不到模块'commander'
- java - 如何在java中获取4周前的所有日期
- javascript - 在 MessageEmbed 中使用基于用户存在状态的自定义表情符号
- jquery - 跨度点击功能不起作用(很棒的字体星级评分系统)
- flutter - Flutter - 屏幕的多个文件?
- elasticsearch - logstash 没有将日志推送到 AWS Elasticsearch
- python - Matplotlib 和 OpenCV 导致崩溃
- jquery - J查询数据表销毁并重新创建
- android - 当 setDisplayHomeAsUpEnabled 为 true 时,折叠的工具栏标题不居中
- html - 盒子阴影在 Mozilla 中不起作用