Database

[{username:"jack",events:[{eventType:"party",createdAt:"2022-01-23T10:26:11.214Z",visitorInfo:{location:{country:"US"}}},{eventType:"party",createdAt:"2022-01-30T10:26:11.214Z",visitorInfo:{location:{country:"US"}}},{eventType:"party",createdAt:"2022-01-29T10:26:11.214Z",visitorInfo:{location:{country:"US"}}},{eventType:"meeting",createdAt:"2022-01-29T10:26:11.214Z",visitorInfo:{location:{country:"US"}}},{eventType:"meeting",createdAt:"2022-01-31T10:16:11.214Z",visitorInfo:{location:{country:"GB"}}},{eventType:"meeting",createdAt:"2022-01-31T10:16:11.214Z",visitorInfo:{location:{country:"GB"}}},{eventType:"party",createdAt:"2022-01-31T10:16:10.214Z",visitorInfo:{location:{country:"GB"}}}]}]

Query

db.collection.aggregate([{$unwind:"$events"},{$project:{party:{$cond:[{$eq:["$events.eventType","party"]},1,0]},meeting:{$cond:[{$eq:["$events.eventType","meeting"]},1,0]},country:"$events.visitorInfo.location.country"}},{$group:{_id:"$country",meeting:{$sum:"$meeting"},party:{$sum:"$party"}}},{$project:{country:"$_id",meeting:1,party:1}},{$group:{_id:"cc",countryAndEventFrequency:{$push:"$$ROOT"}}},{$project:{_id:0,countryAndEventFrequency:1}}])

Result