I'm 2 hours into Mongo/Monk with node.js and I want to count how many objects I have inserted into a collection but I can't see any docs on how to do this with Monk.
Using the below doesn't seem to return what I expect
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/mydb');
var collection = db.get('tweets');
collection.count()
Any ideas?
You need to pass a query and a callback. .count()
is asynchronous and will just return a promise, not the actual document count value.
collection.count({}, function (error, count) {
console.log(error, count);
});