【问题标题】:How to get all ids to pouchdb's documents using node.js如何使用 node.js 获取 pouchdb 文档的所有 id
【发布时间】:2020-05-30 21:41:41
【问题描述】:

我想知道如何使用 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);
 });

【问题讨论】:

    标签: javascript node.js database pouchdb


    【解决方案1】:

    试试这样的

    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);
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      相关资源
      最近更新 更多