In MongoDB, does .find({...}).limit(#) really limit the number of queries?
I mean, when you do db.collection.find(condition), doesn't it already waste computational power to query all the results that match the given condition? If so, then does adding .limit() after it just strip off the unneeded elements from the query results?
Thanks a lot for clarifying this up!
db.collection.find returns a cursor, not an array of results or similar. From the documentation:
When the
find()method “returns documents,” the method is actually returning acursorto the documents.
The documents are actually located when you iterate the cursor. So calling .limit tells the cursor when to say it's done iterating.
More about cursors here: http://docs.mongodb.org/manual/core/cursors/#read-operations-cursors
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