I need to get all the documents from PouchDB database . Can anyone tell me how to get the 'doc' from the callback function? I would like to return it as response object and also to get it in console output.
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);
});
                I think what you want is the following:
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);
});
If there is an error it will be handled by your catch callback, so you only have one parameter (result) in your then callback. The result variable will include some metadata about the results (e.g. total_rows) as well as a rows property which will be an array of all of the documents in your database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With