I have 2 collection: Company
and Stores
. I used $lookup
on Store
collection using the storeIds
on Company
collection. I need to pass 'Company.Year' value to Stores.Statuses.Year inside $Match
operator. Any help is appreciated.
Company: [
{
"_id": {
"$oid": "1388445c0000000000000001"
},
"name": "Company A",
"year": 2022,
"storeIds": [
{
"$oid": "1388445c0000000000000011"
},
{
"$oid": "1388445c0000000000000012"
}
]
}
]
Store: [
{
"_id": {
"$oid": "1388445c0000000000000011"
},
"name": "Store A",
"statuses": [
{
"year": 2021,
"status": "pending"
},
{
"year": 2022,
"status": "review"
}
]
}
]
Output: [
{
"_id": {
"$oid": "1388445c0000000000000001"
},
"name": "Company A",
"year": 2022,
"storeIds": [
{
"$oid": "1388445c0000000000000011"
}
],
"statuses": [
{
"year": 2022,--->How to pass company.year value instead of hard-coded value(2022).
"status": "review"
}
]
}
]