-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.2.0
-
Component/s: JavaScript, Querying
-
None
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Problem:
MaxKey seems to produce an incorrect match, resulting in returning too many documents.
The explain seems to use the right index, not sure if the evaluation of MaxKey is correct
{
"cursor" : "BtreeCursor fields_1",
"isMultiKey" : true,
"n" : 3,
"nscannedObjects" : 5,
"nscanned" : 5,
"nscannedObjectsAllPlans" : 5,
"nscannedAllPlans" : 5,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"fields" : [
[
{
"key1" : 2
},
{
"key1" : { $maxKey : 1 }
}
]
]
},
"server" : "vero:27017"
}
Reproduce:
db.form.drop();
db.form.insert({"fields" : [ { "key1" : 2 }, { "key2" : "Worlds" } ] })
db.form.insert({"fields" : [ { "key2" : "!" }, { "key5" : "text" } ] })
db.form.insert({"fields" : [ { "key1" : 1 }, { "key2" : "Hello" } ] })
db.form.ensureIndex({fields:1})
> db.form.find({"fields": {$elemMatch: { $gte: {key1:2}, $lt: {key1:MaxKey}}}})
{ "_id" : ObjectId("509c19a9b72f2fa3103bd760"), "fields" : [ { "key1" : 2 }, { "key2" : "Worlds" } ] }
{ "_id" : ObjectId("509c19a9b72f2fa3103bd761"), "fields" : [ { "key2" : "!" }, { "key5" : "text" } ] }
{ "_id" : ObjectId("509c19a9b72f2fa3103bd762"), "fields" : [ { "key1" : 1 }, { "key2" : "Hello" } ] }
This should return only a single object
{ "_id" : ObjectId("509c19a9b72f2fa3103bd760"), "fields" : [ { "key1" : 2 }, { "key2" : "Worlds" } ] }