MongoDB count() undefined

I'm very newbie on Javascript-NodeJS-MongoDB, I try to know the number of documents found by a query.

var page =;  

var db = require('mongojs').connect('localhost:27017/foo', ['bar']); 

var docs ={x:'MME'}).sort({y:1}).skip(10*(page-1)).limit(10); 

var nbDocs ={x:'MME'}).count(); /*docs.count();*/


But unfortunately the log gives me 'undefined', the same if I code

var nbDocs = docs.count();

Thank's a lot for your precious help.



According to the docs the result will be in the second argument of the callback to the cursor.count() method. This might be a little more challenging to implement for somebody who's new to javascript, but I think something like this should work:

docs.count(function(error, nbDocs) {
    // Do what you need the count for here.

Need Your Help

What's the best API for automated forex trading?

api cross-platform trading forex

I am interested in writing a small automatic trader for the forex market. I would like to chose my own tools (platform and programming language) and I just need to find a decent API to query the nu...

How do I focus a modal WPF Window when the main application window is clicked

c# wpf window

I have my MainApplication Window that launches a new Window with .ShowDialog() so that it is modal.