How to make pagination with mongoose

I want to make a pagination feature in my Collection. How can find a documents with 'start' and 'limit' positions and get total document number in a single query?

You can't get both results in one query; the best you can do is to get them both using one Mongoose Query object:

var query = MyModel.find({});
query.count(function(err, count) {...});
query.skip(5).limit(10).exec('find', function(err, items) {...});

Use a flow control framework like async to cleanly execute them in parallel if needed.

If you plan to have a lot of pages, you should not use skip/limit, but rather calculate ranges.

See Scott's answer for a similar question: MongoDB - paging

UPDATE :

Using skip and limit is not good for pagination. Here is the discussion over it.

@Wes Freeman, Gave a good answer. I read the linked pose, you should use range query. n = 0; i = n+10; db.students.find({ "id" : { $gt: n, $lt: (n+i)} } );

OLD ANSWER (don't use this)

use something like

n = db.students.find().skip(n).limit(10);
//pass n dynamically, so for page 1 it should be 0 , page 2 it should be 10 etc

more documentation at http://www.mongodb.org/display/DOCS/Advanced+Queries