【发布时间】:2013-10-11 15:47:48
【问题描述】:
我有一个表单集合
{
"fieldA":"ValueA",
"fieldB":"ValueB"
}
其中 fieldA 始终存在于文档中,但 fieldB 可能存在也可能不存在于文档中。
我们还假设我在 fieldA 上有一个名为 fieldAIndex 的索引
现在有了这个索引,我希望 fieldAIndex 完全覆盖下面的查询
db.collection.find({"fieldA":"Value1"},{"_id":0,"fieldA":1})
使用 explain() 运行证实了这种情况:
{
"indexOnly" : true
}
但是当我运行以下查询时令人惊讶:
db.collection.find({"fieldA":"Value1","fieldB":{"$exists":true}},{"_id":0,"fieldA":1})
解释也返回
{
"indexOnly" : true
}
鉴于 fieldB 不在索引中,查询如何仅从索引中返回?索引是否包含有关存在的字段的信息或解释是否返回不正确?
提前致谢,
马特。
【问题讨论】:
-
这可能是因为jira.mongodb.org/browse/SERVER-5759中报告的错误
-
看起来我遇到了同样的问题。感谢您的链接。
标签: mongodb indexing exists explain