假设我添加了一个文档
db.search.save({terms:["10115","Berlin","Germany"]})
我通过以下方式添加了一个索引:
db.search.ensureIndex({terms:1})
当搜索文档并确保只获取索引时
db.search.find({terms:"Berlin"}, {terms:1,_id:0}).explain()
# note: causes the whole output of the array, which might cause some trouble?
# however, leaving it out doesn't change anything
我希望在 .explain() 内
"indexOnly" : true
游标表示mongo正在使用索引(BtreeCursor terms_1)。 所以我想知道 mongo 是否能够仅通过触摸索引来输出数组索引。
最后我想做一个查询,例如:
db.search.find({terms:{$all:[/10115/i,/ger/i]}})
PS:我看到对于后者,正则表达式可能会造成一些麻烦……至少那是我的猜测。
感谢您的反馈。
干杯
最佳答案
目前无法在数组上使用覆盖索引。这是因为数组中的每个元素都是单独索引的,因此索引中没有包含整个数组的条目。
关于arrays - MongoDB 和数组上的覆盖索引可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7111078/