【发布时间】:2012-03-28 18:10:46
【问题描述】:
例如,我收集了 foo 这样的文档:
{"tag_cloud":[{"value":"games", "count":10}, {"value":"girls", "count":500}]}
{"tag_cloud":[{"value":"games", "count":5}, {"value":"stack", "count":100}]}
{"tag_cloud":[{"value":"mongodb", "count":1000}, {"value":"thread", "count":15}]}
两种索引有什么区别:
- ensureIndex({"tag_cloud"})
- ensureIndex({"tag_cloud.value"});确保索引({“tag_cloud.count”})
在请求的上下文中:
db.foo.find({"tag_cloud.value":"games"}).sort({"tag_cloud.count":-1});
谢谢!!!
【问题讨论】: