I have a mongo collection as below:
{
"_id" : ObjectId("6225a7b8d06fdc0abe145634"),
"name" : "Max",
"age" : 28,
"salary" : 3000
}
{
"_id" : ObjectId("6225a7b8d06fdc0abe145635"),
"name" : "Manu",
"age" : 25,
"salary" : 4000
}
I have three indexes for this collection:
When I executed a query like db.customers.explain().find({name: "Max", age: 28})
, I was expecting the winningPlan to be the compound index, instead the winning plan was the standalone name_1 index and the rejectedPlan was the compound index.
Can anyone help me understand why is this happening?
Your compound index need to be name_1_age_1 to be possible to be used by the query ...