【发布时间】:2010-09-21 01:37:26
【问题描述】:
如果有索引
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 个字段。
【问题讨论】: