|
This is not an issue with limit, but simply how "$or" clauses work with shared "and" clauses when selecting indexes to use.
If limit is really not returning just the specified count (20) please show an example of that bug, where limit does not work.
See the underlying issue here: SERVER-13732
|
|
Given a collection with the following schema:
> db.sample.find().limit(3).pretty()
|
{
|
"_id" : ObjectId("573de1ba69610a3802f7125b"),
|
"a" : 0,
|
"c" : 76,
|
"b" : 3094
|
}
|
{
|
"_id" : ObjectId("573de1ba69610a3803f7125b"),
|
"a" : 0,
|
"c" : 24,
|
"b" : 3480
|
}
|
{
|
"_id" : ObjectId("573de1ba69610a3805f7125b"),
|
"a" : 2,
|
"c" : 84,
|
"b" : 6964
|
}
|
> db.sample.find().count()
|
1000000
|
> db.sample.createIndex({a:1,b:1,c:1})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
I get the following results:
db.sample.find({a:0,$or:[{b:{$gt:76}},{b:76,c:{$lt:3094}}]}).limit(20).explain(true).executionStats.totalDocsExamined
|
2529
|
when I would have expected the entries plucked from the index to be limited to 20
|