-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.2.2
-
Component/s: Shell
-
None
-
ALL
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
I have a record in my database but it doesn't seem to be indexed correctly.
I have a compound index
{
"v" : 1,
"key" :
,
"ns" : "loco.history",
"name" : "device_1_time_-1"
},
and this is used to run the query.
locobase:SECONDARY> db.history.find({device:357207050859404,"time":{"$gt":start,"$lt":end}}).explain()
{
"cursor" : "BtreeCursor device_1_time_-1",
"isMultiKey" : false,
"n" : 19,
"nscannedObjects" : 19,
"nscanned" : 19,
"nscannedObjectsAllPlans" : 19,
"nscannedAllPlans" : 19,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" :
,
"server" : "uk4.loco-pos.net:27017"
}
note: there are 19 items found
but if I give a hint to not use the time field in the index I get
locobase:SECONDARY> db.history.find({device:357207050859404,"time":{"$gt":start,"$lt":end}}).hint(
{device:1}).explain()
{
"cursor" : "BtreeCursor device_1",
"isMultiKey" : false,
"n" : 19,
"nscannedObjects" : 20,
"nscanned" : 20,
"nscannedObjectsAllPlans" : 20,
"nscannedAllPlans" : 20,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" :
,
"server" : "uk4.loco-pos.net:27017"
}
now there are 20 items.
The missing item has
locobase:SECONDARY> db.history.findOne({_id:ObjectId("533a8bf3d6e909b3c29e6e38")}).time
ISODate("2014-04-01T09:50:43.487Z")
as far as I know, There are no other records with this problem and everything else seems normal.
I realise 2.2.2 is quite old but this may still be relevant.