Database
db={"User_Promo_Map":[{"promo_Id":ObjectId("5e93fea52f804ab99b12e7c0"),"user_Id":ObjectId("5e8c1180d59de1704ce68112"),"amount":"25"},{"promo_Id":ObjectId("5e93fea52f804ab99b12e7c1"),"user_Id":ObjectId("5e8c1180d59de1704ce68112"),"amount":"112"},{"promo_Id":ObjectId("5e93fea52f804ab99b12e7c2"),"user_Id":ObjectId("5e8c1180d59de1704ce68112")}],"promo":[{"_id":ObjectId("5e93fea52f804ab99b12e7c0"),"platform":"twitch","format":"livestream","description":"Live stream - 1 minute feature","active":true},{"_id":ObjectId("5e93fea52f804ab99b12e7c4"),"platform":"twitch","format":"livestream","description":"Live stream - 5 minute feature","active":false},{"_id":ObjectId("5e93fea52f804ab99b12e7c1"),"platform":"youtube","format":"livestream","description":"Live stream - 4 minute feature","active":true},{"_id":ObjectId("5e93fea52f804ab99b12e7c2"),"platform":"facebook","format":"livestream","description":"Live stream - 2 minute feature","active":true},{"_id":ObjectId("5e93fea52f804ab99b12e7c3"),"platform":"facebook","format":"livestream","description":"Live stream - 3 minute feature","active":true},{"_id":ObjectId("5e93fea52f804ab99b12e7c5"),"platform":"facebook","format":"livestream","description":"Live stream - 7 minute feature","active":true}],"users":[{"_id":ObjectId("5e8c1180d59de1704ce68112"),"name":"Donald Captain","gender":"male"}]}
Query
db.User_Promo_Map.aggregate([{$match:{user_Id:ObjectId("5e8c1180d59de1704ce68112")}},{$lookup:{from:"promo",pipeline:[{$match:{active:true,platform:{$in:["twitch","youtube","facebook"]}}}],as:"accountsData"}},{$unwind:"$accountsData"},{$group:{_id:"$accountsData.platform",data2:{$addToSet:{amount:"$amount",promo_Id:"$promo_Id"}},data:{$addToSet:{_id:"$accountsData._id",format:"$accountsData.format",description:"$accountsData.description"}}}},{$addFields:{data:{$map:{input:"$data",as:"data",in:{"_id":"$$data._id","description":"$$data.description","format":"$$data.format",amount:{$reduce:{input:"$data2",initialValue:"$$REMOVE",in:{$cond:[{$eq:["$$this.promo_Id","$$data._id"]},"$$this.amount","$$value"]}}}}}}}},{$group:{_id:null,data:{$push:{k:{$toString:"$_id"},v:"$data"}}}},{$replaceRoot:{newRoot:{$arrayToObject:"$data"}}}])