Closed millerbryan closed 8 years ago
After digging deeper into the body object I can use this
var count = 0;
for(var prop in body.rows) {
if(body.rows.hasOwnProperty(prop))
++count;
}
but it isn't elegant.
You can use the db.get
endpoint to return you meta information about a database as a whole without fetching all the documents. The meta data looks something like this:
{
db_name: 'animaldb',
doc_count: 12,
doc_del_count: 7,
update_seq: 25,
purge_seq: 0,
compact_running: false,
disk_size: 57455,
data_size: 7210,
instance_start_time: '1473786786592693',
disk_format_version: 6,
committed_update_seq: 25
}
Here's some code:
var cloudant = require('cloudant')({url:"http://localhost:5984"});
cloudant.db.get("animaldb", function(err, data) {
console.log(data.doc_count);
});
Very nice! Thank you Glenn. Do you mind if I add that to the docs?
I see an example using
db.list()
but it is not clear what is returned.Is
body.rows
an object or an integer?