如何为多列范围查询创建复合索引

时间:2011-05-09 17:53:31

标签: mongodb indexing range nosql

我想对多个列进行范围查询。例如:

db.dmnscore.find({price:{$ lte:10},“updated”:{“$ gte”:new 日期(1304874799000)},“得分”:{“$ gte”:0,“$ lte”: 1000})排序({分数:-1}) 是否可以为此查询创建合适的复合索引?

由于

1 个答案:

答案 0 :(得分:0)

最简单的方法是自己测试一下。在属性上创建索引,然后运行此查询:

db.dmnscore.find({price:{$lte:10}, "updated" : {"$gte" : new Date(1304874799000)} ,"score" : {"$gte" : 0,"$lte" : 1000}).sort({score:-1}).explain()

注意到最后的explain()。如果结果中包含Btree,那么如果结果包含BasicCursor,则表示它没有使用索引。

相关问题