What does limit() do?
limit() restricts the number of documents a query returns.
Example:
js
db.users.find().limit(5)This query returns only 5 documents, even if the collection has thousands.
Why it's used:
- to avoid pulling too much data at once
- to speed up the query
- it's handy for pagination (e.g. by page)
Summary: limit() is a cap on how many results come back.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.