1

My query is

db.new.find({'a':{'$gt':200}, 'b':{'$lt': 30}}, 
            {'a':1, 'c':1}
).sort({'c':-1})

Indexes present are (a,b), (a,c), (c), (a,b,c), (_id)

When I check with explain('allPlansExecution'), I see that the index on _id is not used anywhere. However, since _id has not been suppressed in the projection, shouldn't it be used? Is there any possibility of it being used implicitly in such cases?

0

No, there is no need (in that query) to use _id index. There is no sort nor selection what need that index. Second, index (a,b) is not needed, it takes space and extra effort to keep updated. Index (a,b,c) answers all questions when keys a and b is queried.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.