Hi there,
I have been trying to get this right but unable.
I have the following data in my collection:
{
"_id": {
"$oid": "6786a209d6b086487098e54b"
},
"date": {
"$date": "2024-01-02T00:00:00.000Z"
},
"hour": 12,
"numRegistrations": 2,
"totalValue": 110,
"company": "1886",
"partners": [{
"id": 14,
"numRegistrations": 1,
"totalvalue": 90
}, {
"id": 7,
"numRegistrations": 1,
"totalValue": 20
}]
}
I am using aggregate to match elements. My difficulty is to write the $match when the “partners” has specific “id”. For example: 14. I want to filter the elements where “partners.id” = 14. The problem is that partners is an array of objects.
My query works well if I don’t add the partners. If I do, it just ignores it and brings back all records for all partners.id:
query= [{“$match”:{“date”:{“$gte”:“2024-01-01T00:00:00.000Z”,“$lte”:“2024-01-03T23:59:59.000Z”},“site”:“1886”,“partners.id”:14}}]
What am I missing? Many thanks.