It seems that the behavior for limit on cursors both in the mongodb shell and any drivers , but also if you apply a stream is as follow:> db.things.find({}).count();7394> db.things.find({}).limit(3).size();3> db.things.find({}).limit(2).size();2> db.things.find({}).limit(1).size();1> db.things.find({}).limit(0).size();7394> db.things.find({}).limit(-1).size();1> db.things.find({}).limit(-2).size();2> db.things.find({}).limit(Infinity).size();0So basically if you limit to zero you get ALL the items in a collection and if you limit to Infinity you get zero. Is there a rationale behind this design choice?
Your intuition reflects another sensible way to handle it. Without having been a part of the initial choice myself, one issue in favor of the current approach is trying to keep behavior consistent across languages - for someone using mongodb from a language without an infinity primitive, they should also have an easy way to specify all results within the context of a limit, and there should be minimal change from language to language. Limit 0 meaning all records in some languages and none in others would cause confusion.
In this case a zero limit is treated in a sense like a null limit. I recognize that some will find that counterintuitive, but there wasn't an obvious alternative for many other languages.
Infinity primitive in js not being implemented to have an intuitive behavior I bet is just work not done in favor of other work. Not trivial without an infinity primitive in c++ see http://stackoverflow.com/questions/8690567/setting-an-int-to-infinity-in-c I am sure there are reasonable solutions but not sure at this point in the product cycle it is worth bothering vs implementing something else given another working solution.
Good question, thx.
-- Max
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.