What does a negative value for limit
operator mean?
http://www.mongodb.org/display/DOCS/Aggregation+Framework+-+$limit
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Blimit%28%29%7D%7D
Mongo returns the same exact document when I do limit(1)
or limit(-1)
??
If the limit number is negative, then generally the database will return that number of results and close the cursor - essentially a single batch of results is returned and no further results for that query can be fetched.
As for the less general case, if the negative limit value exceeds the batch size (particularly the max batch size), then the batch will be returned and the cursor closed whether the limit has been reached or not. Hence, the single batch rule trumps the limit specified if the limit is too high.
If the limit is positive you can leave the cursor open to receive further results and continue to iterate until the cursor is exhausted.
For more on batches and cursors, take a look here:
http://docs.mongodb.org/manual/core/cursors/#cursor-batches http://docs.mongodb.org/manual/reference/method/cursor.limit/#negative-values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With