Javascript 如何将所有ID发送到数据库';使用node.js创建文档

Javascript 如何将所有ID发送到数据库';使用node.js创建文档,javascript,node.js,database,pouchdb,Javascript,Node.js,Database,Pouchdb,我想知道如何使用node.js从PockDB获取某个数据库的所有ID 这是我的尝试,但是你可以猜到它没有起作用,特别是我需要把所有的ID放入一个数字数组中,只有ID没有别的。我是javascript和数据库的初学者 var PouchDB = require('PouchDB'); var db = new PouchDB('mes_iab_db'); db.allDocs({ include_docs: true, attachments: true }).then(funct

我想知道如何使用node.js从PockDB获取某个数据库的所有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);
  });

试试这样的

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