如果有索引
page_type, our_id, date
查询时,
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()
如果our_id
被省略,或者date
被省略,它仍然可以使用索引,在 explain() 输出中类似于以下内容:
"our_id" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
即使两者our_id
都date
省略,索引仍然可以使用。
但是,如果page_type
省略,则不能使用索引(如 所示explain()
)。那么在 MongoDB 中,当索引的一部分是序列的东西,比如数字或日期时,是否真的可以在查询时省略它?这在关系数据库中也是如此吗,因为我认为如果该索引基于这 3 个字段,它可能严格在 3 个字段上。