Database IntegrationLesson 69Free preview
MongoDB Limit
This lesson is part of Node.js · All levels
Summary
This lesson discusses limiting the number of MongoDB query results using limit() and skip() on the find cursor. With the page-1*limit pattern you can build a memory-saving pagination. You also learned that a limit without a stable sort can make the results between calls inconsistent.
Key points
- Limit(n) limits the result to n documents; skip(n) passes the first n documents.
- Pagination: skip = (page - 1) * limit.
- Combine with sort() so that the results of the pages do not overlap.
- The minimum + limit projection column presses the network payload.
- For large feeds, _id-based or cursor-based pagination is usually more stable than large skip.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.