There is the following array of objects:
let externalArray =
[
{ name: "xxx",
max: 100,
unit: "myUnit"
},
{ name: "yyy",
max: 90,
unit: "myUnit"
}
]
And the following mongodb structure:
[
{
"myList": [
{
"name": "xxx",
"amount": 66.3,
"unit": "myUnit"
},
{
"name": "yyy",
"amount": 11.6,
"unit": "myUnit"
},
{
"name": "zzz",
"amount": 6.9,
"unit": "myUnit"
}
]
}
]
How can I use the $match query inside an aggregation to only output the objects for which myList.amount <= externalArray.max and myList.unit equals externalArray.unit for the same name? Thank you so much for your help.