Database

db={"event":[{username:"jack",events:[{eventType:"party",createdAt:"2022-01-23T10:26:11.214Z",visitorInfo:{visitorId:"87654321-0ebb-4238-8bf7-87654321"}},{eventType:"party",createdAt:"2022-01-30T10:26:11.214Z",visitorInfo:{visitorId:"87654321-0ebb-4238-8bf7-87654321"}},{eventType:"party",createdAt:"2022-01-29T10:26:11.214Z",visitorInfo:{visitorId:"12345678-0ebb-4238-8bf7-12345678"}},{eventType:"party",createdAt:"2022-01-31T10:16:11.214Z",visitorInfo:{visitorId:"12345678-0ebb-4238-8bf7-12345678"}}]}]}

Query

db.event.aggregate([{"$match":{username:"jack"}},{"$addFields":{"totalVisitors":{"$reduce":{"input":"$events","initialValue":0,"in":{"$cond":{"if":{$eq:["$$this.eventType","party"]},"then":{$add:["$$value",1]},"else":"$$value"}}}}}},{$unwind:"$events"},{$match:{"events.eventType":"party"}},{$group:{_id:"$events.visitorInfo.visitorId",count:{$sum:1},totalVisitors:{$first:"$totalVisitors"}}},{$group:{_id:null,count:{$first:"$count"},totalVisitors:{$first:"$totalVisitors"}}}])

Result