Database

[{"group":"A","count":6,"total":20,"_":true},{"group":"B","count":2,"total":50,"_":true},{"group":"A","count":4,"total":80,"_":false},{"group":"C","count":12,"total":60,"_":false}]

Query

db.collection.aggregate([{$facet:{first:[{$match:{"_":true}}],second:[{$match:{"_":false}}],}},{$project:{all:{$concatArrays:["$first","$second"]}}},{$unwind:"$all"},{$group:{_id:"$all.group",count:{$sum:"$all.count"},total:{$sum:"$all.total"},}},{$project:{_id:0,group:"$_id",count:1,total:1,avg:{$divide:["$total","$count"]}}}])

Result