2
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:我看到,後者正則表達式可能會引起一些麻煩......至少那是我的猜測。
感謝您的反饋。
乾杯
我有這個想法(見我的筆記)。我也做了一些測試,似乎沒有獲取術語字段沒有任何區別...除非有任何魔術技巧:) – fightbulc