Вы можете использовать ниже агрегации
db.collection.aggregate([
{ "$facet": {
"checkouts": [
{ "$unwind": "$checkouts" },
{ "$group": {
"_id": {
"_id": "$_id",
"date": { "$dateToString": { "date": "$waitlist.date", "format": "%Y-%m" }}
}
},
"checkouts": { "$sum": 1 }
}},
{ "$replaceRoot": {
"newRoot": {
"$mergeObjects": ["$$ROOT", "$_id"]
}
}}
],
"waitlist": [
{ "$unwind": "$waitlist" },
{ "$group": {
"_id": {
"_id": "$_id",
"date": { "$dateToString": { "date": "$waitlist.date", "format": "%Y-%m" }}
},
"waitlist": { "$sum": 1 }
}},
{ "$replaceRoot": {
"newRoot": {
"$mergeObjects": ["$$ROOT", "$_id"]
}
}}
]
}},
{ "$project": {
"data": {
"$concatArrays": ["$checkouts", "$waitlist"]
}
}},
{ "$unwind": "$data" },
{ "$replaceRoot": { "newRoot": "$data" }},
{ "$group": {
"_id": { "_id": "$_id", "date": "$date" },
"waitlist": { "$sum": "$waitlist" },
"checkouts": { "$sum": "$checkouts" }
}}
])