Database

db={"customers":[{"_id":"cust100","name":"Jane Doe","email":"jane@example.com"},{"_id":"cust101","name":"John Smith","email":"john@example.com"}],"orders":[{"_id":"ord200","customerId":"cust100","itemIds":["item300","item301"]},{"_id":"ord201","customerId":"cust101","itemIds":["item302"]},{"_id":"ord202","customerId":"cust100","itemIds":["item301","item303"]}],"items":[{"_id":"item300","name":"Bluetooth Speaker","price":99.99},{"_id":"item301","name":"Wireless Mouse","price":20.50},{"_id":"item302","name":"Keyboard","price":45.00},{"_id":"item303","name":"USB-C Charging Cable","price":12.99}]}

Query

db.customers.aggregate([{$lookup:{from:"orders",localField:"_id",foreignField:"customerId",as:"orders"}},{$unwind:"$orders"},{$lookup:{from:"items",localField:"orders.itemIds",foreignField:"_id",as:"orders.items"}},{$unwind:"$orders.items"},{$group:{_id:{customerId:"$_id",orderId:"$orders._id"},customerName:{$first:"$name"},customerEmail:{$first:"$email"},items:{$push:{itemId:"$orders.items._id",itemName:"$orders.items.name",itemPrice:"$orders.items.price"}},orderTotal:{$sum:"$orders.items.price"}}},{$group:{_id:"$_id.customerId",name:{$first:"$customerName"},email:{$first:"$customerEmail"},orders:{$push:{orderId:"$_id.orderId",items:"$items",total:"$orderTotal"}},totalSpent:{$sum:"$orderTotal"}}}])

Result