Database

[{"owner":1,"location":"Goa","budget":"1 Cr and Above","project":"ABC"},{"owner":1,"location":"Goa","budget":"10 - 30 Lacs","project":"ABC"},{"owner":1,"location":"Mumbai","budget":"30 - 50 Lacs","project":"XYZ"},{"owner":2,"location":"Delhi","budget":"30 - 50 Lacs","project":"ABC"},{"owner":2,"location":"Delhi","budget":"1 Cr and Above","project":"DEF"},{"owner":2,"location":"Delhi","budget":"30 - 50 Lacs","project":"ABC"},{"owner":2,"location":"Goa","budget":"30 - 50 Lacs","project":"ABC"},{"owner":3,"location":"Goa","budget":"70 - 90 Lacs","project":"DEF"},{"owner":3,"location":"Mumbai","budget":"70 - 90 Lacs","project":"XYZ"},{"owner":4,"location":"Bangalore","budget":"2 Cr and Above","project":"DEF"},{"owner":4,"location":"Goa","budget":"2 Cr and Above","project":"ABC"}]

Query

db.collection.aggregate([{$facet:{budgets:[{"$group":{"_id":{"owner":"$owner","budget":"$budget"},budgetCount:{$sum:1}}},{"$group":{"_id":{"owner":"$_id.owner"},budgets:{"$addToSet":{budget:"$_id.budget",count:"$budgetCount"}},totalBudgets:{$sum:"$budgetCount"},}},{$project:{owner:"$_id.owner",_id:0,budgets:1,totalBudgets:1,locations:null,projects:null}}],locations:[{"$group":{"_id":{"owner":"$owner","location":"$location"},locationsCount:{$sum:1}}},{"$group":{"_id":{"owner":"$_id.owner"},locations:{"$addToSet":{location:"$_id.location",count:"$budgetCount"}},totalLocations:{$sum:"$locationsCount"},}},{$project:{owner:"$_id.owner",_id:0,locations:1,totalLocations:1,budgets:null,projects:null}}],projects:[{"$group":{"_id":{"owner":"$owner","project":"$project"},projectsCount:{$sum:1}}},{"$group":{"_id":{"owner":"$_id.owner"},projects:{"$addToSet":{project:"$_id.project",count:"$projectsCount"}},totalProjects:{$sum:"$projectsCount"},}},{$project:{owner:"$_id.owner",_id:0,projects:1,totalProjects:1,budgets:null,locations:null}}],}},{$project:{data:{"$concatArrays":["$budgets","$locations","$projects"]}}},{$unwind:"$data"},{$group:{_id:"$data.owner",locations:{$push:{$ifNull:["$data.locations","$$REMOVE"]}},budgets:{$push:{$ifNull:["$data.budgets","$$REMOVE"]}},projects:{$push:{$ifNull:["$data.projects","$$REMOVE"]}},totalBudgets:{$sum:"$data.totalBudgets"},totalLocations:{$sum:"$data.totalLocations"},totalProjects:{$sum:"$data.totalProjects"},}},{"$project":{"_id":0,"owner":"$_id","locations":{"$arrayElemAt":["$locations",0]},"projects":{"$arrayElemAt":["$projects",0]},"budget":{"$arrayElemAt":["$budgets",0]},totalBudgets:1,totalLocations:1,totalProjects:1}}])

Result