Database

[{"id":"1","month":"Jan","deliveryPartner":{"name":"Lalamove"},"country":"ID"},{"id":"2","month":"Jan","deliveryPartner":{"name":"Lalamove"},"country":"ID"},{"id":"3","month":"Jan","deliveryPartner":{"name":"Borzo"},"country":"ID"},{"id":"4","month":"Jan","deliveryPartner":{"name":"Lalamove"},"country":"PH"},{"id":"5","month":"Jan","deliveryPartner":{"name":"Borzo"},"country":"PH"},{"id":"6","month":"Feb","deliveryPartner":{"name":"Borzo"},"country":"ID"},{"id":"7","month":"Feb","deliveryPartner":{"name":"Borzo"},"country":"ID"},{"id":"8","month":"Feb","deliveryPartner":{"name":"Lalamove"},"country":"PH"}]

Query

db.collection.aggregate([{$match:{"deliveryPartner.name":{$ne:null},"country":{$ne:null},"month":{$ne:null}}},{$group:{_id:{deliveryPartner:"$deliveryPartner.name",country:"$country",month:"$month"},count:{$sum:1}}},{$addFields:{monthIndex:{$indexOfArray:[["Jan","Feb","Mar","Apr"],"$_id.month"]}}},{$setWindowFields:{sortBy:{monthIndex:1},output:{actualMonths:{$addToSet:"$_id.month",window:{documents:["unbounded","unbounded"]}}}}},{$group:{_id:{deliveryPartner:"$_id.deliveryPartner",country:"$_id.country"},monthData:{$push:{month:"$_id.month",count:"$count"}},actualMonths:{$first:"$actualMonths"}}},{$set:{monthData:{$reduce:{input:"$actualMonths",initialValue:"$monthData",in:{$concatArrays:["$$value",{$cond:[{$in:["$$this","$monthData.month"]},[],[{count:0,month:"$$this"}]]}]}}},actualMonths:"$$REMOVE"}}])

Result