Mongoose: how to implement pagination? Mongoose: how to implement pagination? mongoose mongoose

Mongoose: how to implement pagination?


Your 1st solution is OK if you don't want to show number of pages but you need to get the count if you want to get number of pages numberOfPages = count/numberPerPage so you will run count() at least once at beginning so you query "or more if you want to be update with this information while user use paged data {I'll ignore this for simplicity if it is critical for you please comment here and lets discuss it}".

so the first query will take sometime here a link about issue on MongoDB about count performance telling that they make improvements for this method https://jira.mongodb.org/browse/SERVER-1752 .