how to make compound index for multiple column range queries
I want to make a r开发者_Go百科ange query on multiple columns. for example:
db.dmnscore.find({price:{$lte:10}, "updated" : {"$gte" : new Date(1304874799000)} ,"score" : {"$gte" : 0,"$lte" : 1000}).sort({score:-1}) Is it possible to make a proper compound index for this query?
Thanks
The easiest thing is to test it yourself. Create an index on the properties, then run this query:
db.dmnscore.find({price:{$lte:10}, "updated" : {"$gte" : new Date(1304874799000)} ,"score" : {"$gte" : 0,"$lte" : 1000}).sort({score:-1}).explain()
notice the explain()
on the end. If the result contains Btree
you're good, if the result contains BasicCursor
it hasn't used the index.
精彩评论