Three chainable methods control the shape of a find() result: sort() orders it, limit() caps how many documents come back, and skip() discards a number of results from the start — the combination used to build pagination.
Pass a field with 1 for ascending or -1 for descending:
// Oldest to youngest
db.users.find().sort({ age: 1 })
// Youngest to oldest
db.users.find().sort({ age: -1 })Caps the number of documents returned — useful for "top 5" style results, and for keeping large collections from returning everything at once:
db.users.find().sort({ age: -1 }).limit(5)Skips a number of documents before returning results — combined with limit(), this is exactly how pagination works:
// Page 2, 10 results per page: skip the first 10, then take 10
db.users.find().sort({ name: 1 }).skip(10).limit(10)MongoDB always applies sort, then skip, then limit internally regardless of the order you chain them in the shell — but writing them in that order (.sort().skip().limit()) makes the query read the same way it actually behaves, which matters when someone else reads your code later.
skip() is fine for typical pagination
For real pagination, calculate skip as (pageNumber - 1) * pageSize. Skipping a very large number of documents gets slower as the number grows, since MongoDB still has to walk past every skipped document — for deep pagination on large collections, a different technique (cursor-based pagination) works better, but skip() is fine for typical page sizes.