I’m trying to perform aggregation for the following:
MONTHLY_COLLECTION
{
"month_year" : "01-2020",
"dates" : {
"1": [ new ObjectId("1"), new ObjectId("2") ], // array of Booking Collection IDS
"5": [ new ObjectId("3")],
...
},
BOOKING_COLLECTION
{
"_id": 1 ,
...
},
{
"_id": 57 ,
...
},
{
"_id": 2 ,
...
},
{
"_id": 3 ,
...
},
...
desired output:
{
"_id": 1 ,
...
},
{
"_id": 2 ,
...
},
{
"_id": 3 ,
...
},
such that I get only the booking documents which fall within the given month_years.dates
db.collection(MONTHLY_COLLECTION).aggregate([
{
"$match": { month_year: { "$in": [`01-2023`, `08-2023`] } },
},
???
])
so how do I iterate over the keys in an object and then iterate over their individual arrays via $lookup?