Malaka
Malaka

Reputation: 107

Return all documents from Cloudant db through nodeJs

Passing null or an empty Json to the selector does not seem to work. I am trying to get all the data in a database. Tried:

 db.list({}, function (err, data) {
        if (err) {
            return console.log("Error:",err.message);
        }
        console.log(data);
    });
    db.find(null, function (err, data) {
        if (err) {
            return console.log("Error:",err.message);
        }
        console.log(data);
    });
    db.bulk({docs:[]}, function (err, data) {
        if (err) {
            return console.log("Error:",err.message);
        }
        console.log(data);
    });

Upvotes: 3

Views: 6120

Answers (1)

Glynn Bird
Glynn Bird

Reputation: 5637

To get a list of all the documents, don't pass anything at all e.g.

db.list(function (err, data) {
  console.log(err, data);
});

If you want the document bodies too, then pass in include_docs=true:

db.list({include_docs:true}, function (err, data) {
  console.log(err, data);
});

This mirrors the CouchDB API for the GET /db/_all_docs endpoint - without any parameters, you get all the document ids and revision tokens.

Upvotes: 8

Related Questions