Database

[{"postType":"buy","product":"3",},{"postType":"view","product":"4",},{"postType":"buy","product":"2",},{"postType":"view","product":"2",},{"postType":"share","product":"3",},{"postType":"buy","product":"2",},{"postType":"buy","product":"2",},{"postType":"share","product":"2",},{"postType":"buy","product":"1",},{"postType":"buy","product":"1",},{"postType":"viewvideo","product":"1",},{"postType":"viewvideo","product":"2",},{"postType":"viewvideo","product":"3",},{"postType":"buy","product":"4",},{"postType":"buy","product":"5",}]

Query

db.collection.aggregate([{$group:{_id:{postType:"$postType",product:"$product"},count:{$count:{}}}},{$group:{_id:"$_id.product",data:{$push:"$$ROOT"}}},{$project:{_id:0,product:"$_id",data:{$arrayToObject:{$map:{input:"$data",in:{k:"$$this._id.postType",v:"$$this.count",}}}}}},{$replaceWith:{$mergeObjects:["$$ROOT","$data"]}},{$unset:"data"}])

Result