Hello all,
I am working with mongodb 4.4 and i am faced with strange behavior.
I run a this very simple aggregate in a collection that contains actually 30 millions of documents :
db.ECRITURE.aggregate([
{ "$match": {
"A_ECR_01": "01",
"A_ECR_02": "02"
} },
{ "$group": {
"_id": {"$concat": ["$A_ECR_01", "_", "$A_ECR_02" , "_", "$A_ECR_03"]},
"A_CHN_ACH_011":{
"$sum":{
"$cond":[
{
"$in":[
"$codRegroupement",
[
"DEB_SST"
]
]
},
"$A_CHN_ACH_011",
null
]
}
}
} }
])
On my collection i have a compound index on A_ECR_01, A_ECR_02, A_ECR_03. But this aggregate takes about 30s.
But if i execute this same aggregate on a collection containing only the documents for “A_ECR_01”: “01” and “A_ECR_02”: “02” it takes 1s.
Note : there is around 500K documents in the collections for “A_ECR_01”: “01” and “A_ECR_02”: “02”.
It’s like the match stage doesn’t work well.
Do you have an idea where to investigate ?
Best regards.