Database
db={orders:[{_id:ObjectId("65fee31937b6938d0107afe9"),products:[{_id:ObjectId("65fee0f137b6938d0107afe3"),qty:20},{_id:ObjectId("65fee0f137b6938d0107afe4"),qty:2}],uid:ObjectId("65fee0b337b6938d0107afe1")},{_id:ObjectId("65fee31937b6938d0107afea"),products:[{_id:ObjectId("65fee0f137b6938d0107afe2"),qty:4},{_id:ObjectId("65fee0f137b6938d0107afe4"),qty:1}],uid:ObjectId("65fee0b337b6938d0107afe0")}],users:[{_id:ObjectId("65fee0b337b6938d0107afe0"),name:"User 1",address:"Address 1"},{_id:ObjectId("65fee0b337b6938d0107afe1"),name:"User 2",address:"Address 2"}],products:[{_id:ObjectId("65fee0f137b6938d0107afe2"),name:"Product 1",price:30},{_id:ObjectId("65fee0f137b6938d0107afe3"),name:"Product 2",price:10},{_id:ObjectId("65fee0f137b6938d0107afe4"),name:"Product 3",price:40}]}
Query
db.orders.aggregate([{$lookup:{from:"users",localField:"uid",foreignField:"_id",as:"userDetails"}},{$unwind:"$userDetails"},{$lookup:{from:"products",localField:"products._id",foreignField:"_id",as:"productDetails"}},{$project:{_id:1,products:{$map:{input:"$products",as:"orderProduct",in:{$mergeObjects:["$$orderProduct",{$arrayElemAt:[{$filter:{input:"$productDetails",as:"product",cond:{$eq:["$$product._id","$$orderProduct._id"]}}},0]}]}}},user:{_id:"$userDetails._id",name:"$userDetails.name",address:"$userDetails.address"}}},{$project:{_id:1,products:{$map:{input:"$products",as:"prod",in:{_id:"$$prod._id",name:"$$prod.name",price:"$$prod.price",/** Assuming prices are stored in products collection or another collection*/qty:"$$prod.qty",total:{$multiply:["$$prod.qty","$$prod.price"]}}}},user:1}}])