Compound index is not being used for aggregation match clause

You have equality match on the field index but you do not have any compound index that has that field as a prefix.

See Performance Best Practices: Indexing | MongoDB Blog and pay attention to the ESR rule.

could be written as

"index" : "5ecec41e1c3b9000e12c1225"

can be simplified to

{
  "auction.date": {
                "$lte": "2022-01-26T23:59:59.999Z" ,
                "$gte": "2021-11-26T00:00:00.000Z"
              }
},

and when these simplifications are done you can forgot the explicit $and and write the whole thing as:

{
  $match :
  {
    "index" : "5ecec41e1c3b9000e12c1225" ,
    "auction.date" :
    {
      "$lte" : "2022-01-26T23:59:59.999Z" ,
      "$gte": "2021-11-26T00:00:00.000Z"
    } ,
    "is50PercentageOffAverage" :
    {
      "$exists" : false
    }
  }
}

Finally, if is50PercentageOffAverage:{$exists:false} is part of you main use-cases you might consider Partial Indexes.

1 Like