2013-09-05 22 views

回答

1

您可以創建在用戶集合的索引:

db.users.ensureIndex({"groups" : 1}) 

如果這樣做,MongoDB中不會當你運行搜索參觀組字段中的每個元素。使用

db.users.find({ groups: 'hockey' }).explain() 

看到使用的索引。

根據查詢,它可能根本不需要檢索用戶記錄。例如,

db.users.count({ groups: "hockey"}) 

是「覆蓋查詢」,並且可以單獨使用索引來回答。有關更多信息,請參閱http://docs.mongodb.org/manual/tutorial/create-indexes-to-support-queries/

相關問題