- Reference >
- mongo Shell Methods >
- Cursor Methods >
- cursor.limit()
cursor.limit()¶
On this page
Definition¶
- cursor.limit()¶
Use the limit() method on a cursor to specify the maximum number of documents the cursor will return. limit() is analogous to the LIMIT statement in a SQL database.
Note
You must apply limit() to the cursor before retrieving any documents from the database.
Use limit() to maximize performance and prevent MongoDB from returning more results than required for processing.
Behavior¶
Supported Values¶
The behavior of limit() is undefined for values less than -231 and greater than 231.
Zero Value¶
A limit() value of 0 (i.e. .limit(0)) is equivalent to setting no limit.
Negative Values¶
A negative limit is similar to a positive limit but closes the cursor after returning a single batch of results. As such, with a negative limit, if the limited result set does not fit into a single batch, the number of documents received will be less than the specified limit. By passing a negative limit, the client indicates to the server that it will not ask for a subsequent batch via getMore.
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.