如何使用node.js将所有ID放入pouchdb的文档中

问题描述 投票:1回答:1

我想知道如何使用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个回答
0
投票

尝试这样的事情

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);
  });
© www.soinside.com 2019 - 2024. All rights reserved.