Hi,
I am learning to use MongoDB on a collection containing documents with the following structure:
{
"_id" : ObjectId("53a18d636171cfe49d7647b6"),
"datetime" : "2011-01-01 00:00:00",
"season" : 1,
"holiday" : 0,
"workingday" : 0,
"weather" : 1,
"temp" : 9.84,
"atemp" : 14.395,
"humidity" : 81,
"windspeed" : 0,
"casual" : 3,
"registered" : 13,
"count" : 16
}
and I have defined 3 indexes:
db.collection.ensureIndex({temp:1})
db.collection.ensureIndex({count:1})
db.collection.ensureIndex({temp:1, count:1})
Based on the fact that the documentation specifies that "MongoDB automatically uses an index that covers a query when possible" [1], I was expecting the following query to be indexOnly:
db.bikes.find({temp: {$gt:23}}, {temp:1, count:1, _id: 0})
Unfortunately, it uses the ({temp: 1}) index and it obviously doesn't cover the query.
Is there any logic under the index used and in what way is Mongo using an index that covers a query?
[1] -
http://docs.mongodb.org/manual/tutorial/create-indexes-to-support-queries/#create-indexes-that-support-covered-queries