i have a collection with these indexes:
> db.message.getIndexKeys()
[
{
"_id" : 1
},
{
"msgid" : 1
},
{
"keywords" : 1,
"msgid" : 1
}
]
and a query like
db.message.find({'keywords': {'$all': ['apple', 'banana']}}).limit(30).explain()
works fine with index
{
"cursor" : "BtreeCursor keywords_1_msgid_1",
"nscanned" : 96,
"nscannedObjects" : 96,
...
}
but when sorting with msgid:
db.message.find({'keywords': {'$all': ['apple', 'banana']}})
.sort({msgid:-1})
.limit(30).explain()
mongodb do not use indexes any more:
{
"cursor" : "BtreeCursor msgid_1 reverse",
"nscanned" : 1784455,
"nscannedObjects" : 1784455,
...
}
any solutions?