Paging Results

A very common method of reducing the number of documents returned is paging. Paging involves specifying a number of documents to skip in the matching set as well as a limit on the documents returned. Then the skip value is incremented each time by the amount returned the previous time.

To implement paging on a set of documents, you need to implement the limit and skip options on the options object. The skip option specifies a number of documents to skip before returning documents. By moving the skip value each time you get another set of documents, you can effectively page through the data set. Also, you should always include a sort option when paging data to ensure that the order is always the same. For example, the following ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.