How to paginate with Mongoose in Node.js ?
How to paginate with Mongoose in Node.js ?
For after that focusing on Mongoose API with the information provided by Rodolphe,I figured out this solution:
MyModel.find(query, fields, { skip: 10, limit: 5 }, function(err, results) { ... });
For Pagination using mongoose, express and jade.
var perPage = 10 , page = Math.max(0, req.param('page')) Event.find() .select('name') .limit(perPage) .skip(perPage * page) .sort({ name: 'asc' }) .exec(function(err, events) { Event.count().exec(function(err, count) { res.render('events', { events: events, page: page, pages: count / perPage }) }) })
You can try do this code:
var query = Model.find().sort('mykey', 1).skip(2).limit(5)
To run the query using exec
query.exec(callback);