If there is an index on
page_type, our_id, date
and when querying,
db.analytics.find({page_type: 'ingredients', ga_date:
{$gte : new Date('Wed Sep 08 2010 12:00:00 GMT-0800')}})
db.analytics.find({page_type: 'ingredients', ga_date:
{$gte : new Date('Wed Sep 08 2010 12:00:00 GMT-0800')}}).explain()
if our_id
is omitted, or date
is omitted, it can still use the index, with something like the following in the explain() output:
"our_id" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
even if both our_id
and date
are omitted, the index can still be used.
However, when page_type
is omitted, no index can be used (as shown in explain()
). So is it true that in MongoDB, when part of the index is something of a sequence, like number or date, then it can be omitted when querying? Is this true in the relational DB as well, because I think it might be strictly on the 3 fields if that index was based on those 3 fields.