Search code examples
mongodbnode.jspaginationmongoose

How to paginate with Mongoose in Node.js?


I am writing a webapp with Node.js and mongoose. How can I paginate the results I get from a .find() call? I would like a functionality comparable to "LIMIT 50,100" in SQL.


Solution

  • After taking a closer look at the Mongoose API with the information provided by Rodolphe, I figured out this solution:

    MyModel.find(query, fields, { skip: 10, limit: 5 }, function(err, results) { ... });