【发布时间】:2011-08-18 16:48:01
【问题描述】:
假设我添加了一个文档
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:我发现对于后者,Regex 可能会造成一些麻烦……至少这是我的猜测。
感谢您的反馈。
干杯
【问题讨论】:
标签: arrays search mongodb indexing