Database
db={"Groups":[{_id:ObjectId("5ee5e346fae4a21e28a81d92"),name:"Housemates"},{_id:ObjectId("5ee5e346fae4a21e28a81d91"),name:"Co-workers"},],"Users":[{_id:ObjectId("5ee493b0989d0f271cdc41c1"),name:"Joulie"},{_id:ObjectId("5ee493b0989d0f271cdc41c3"),name:"Co-Newelle"},{_id:ObjectId("5ee493b0989d0f271cdc41c5"),name:"John"},{_id:ObjectId("5ee493b0989d0f271cdc41c7"),name:"Larry"},],"Members":[{group_id:ObjectId("5ee5e346fae4a21e28a81d91"),user_id:ObjectId("5ee493b0989d0f271cdc41c1"),},{group_id:ObjectId("5ee5e346fae4a21e28a81d91"),user_id:ObjectId("5ee493b0989d0f271cdc41c3"),},{group_id:ObjectId("5ee5e346fae4a21e28a81d92"),user_id:ObjectId("5ee493b0989d0f271cdc41c5"),},{group_id:ObjectId("5ee5e346fae4a21e28a81d92"),user_id:ObjectId("5ee493b0989d0f271cdc41c7"),}]}
Query
db.Members.aggregate([{$lookup:{"from":"Groups","localField":"group_id","foreignField":"_id",as:"groups"}},{$lookup:{"from":"Users","localField":"user_id","foreignField":"_id",as:"users"}},{$unwind:"$groups"},{$unwind:"$users"},{$group:{_id:"$groups._id",group_name:{$first:"$groups.name"},user_info:{$addToSet:{name:"$users.name"}}}}])