Indexed query and sorting

Lets assume we have 2 indexes on collection :
Index 1 - a:1,b:1,c:1
index 2 - d:1

Case 1 :
query on collections :
db.collection.find({“a”:“value” , “b”:“value” ,“c”:“value” }).sort({“d”:1})

1> witch index is used for this query and why ?

For the aggregation query MongoDB can not use index for sort after group , unwind etc stages … in that case what is best option ?

Thank You

What do you think it will use @Maharshi_88068? Use the Explain tab in Compass/Atlas or Mongo Shell to determine this. Let us know your findings.

2 Likes

Interesting.

So I have decided to do the test.

As I thought, the index used is number 1 : a:1,b:1,c:1