我在从 MongoDB 的集合中读取数据时尝试仅使用索引,因为我有一些大文档,而对于这个查询,我只需要一个字段。
事实证明,如果索引是多键索引,我不能让 indexOnly = true 。
这是我做的测试:
db.test.drop()
db.test.insert({a:1})
db.test.ensureIndex({a:1})
db.test.find({a:1}, {_id:0, a:1}).explain()
-> indexOnly = true,isMultiKey = false
db.test.insert({a : [2,3]})
db.test.find({a:1}, {_id:0, a:1}).explain()
-> indexOnly = false,isMultiKey = true
该文档提到了多键索引的一些限制,但没有提到这一点。有人知道如何同时使用多键和 indexonly 吗?