Hi,
I have a very slow aggregation (240 sec), but an index exists, which should match the query perfectly.
If I add a hint to the aggregation with the index name it is blazing fast (0.2 sec) on 120M records.
Now, if I compare the explain output between the aggregation with and without hint, they look the same.
Both use a IXSCAN on the same index.
What am I missing?
MongoDB 5.0.9
Query
db.getCollection('events').aggregate([
{ $match: { 'action':'signed',
'quality':{ $in: [ 'QES', 'AES', 'SES' ] },
'timestamp':{'$gte': ISODate("2023-01-01T00:00:00Z"), '$lt': ISODate("2023-02-01T00:00:00Z")},
'paid_by':"2fa321ccaeab411b95066bd7b6f4588d"}},
{ $project: { _id: 0, 'quality':1}},
{ $group : { _id: '$quality', "count":{$sum:1}}}
])
Index:
db.getCollection('events').createIndex(
{
"action" : 1,
"quality" : 1,
"timestamp" : 1,
"paid_by" : 1,
"user.business_id" : 1,
"user.username" : 1,
"legislation" : 1,
"tsp_type" : 1
},
{
name:"signed_quality_timestamp_paidby_legislation_tsptype",
partialFilterExpression: {
'action': 'signed'
}
}
)