Database
[{"userId":1,"username":"john_doe","password":"$2b$12$3fJyHTgM8QgU.q.tlpNVyOf.hJYfhVe7XPGCHm9Wq1RmexUZbUEeu","fullName":{"firstName":"John","lastName":"Doe"},"age":30,"email":"john.doe@example.com","isActive":true,"hobbies":["reading","traveling"],"address":{"street":"123 Main St","city":"Anytown","country":"USA"},"orders":[{"productName":"Product 1","price":23.56,"quantity":2},{"productName":"Product 2","price":23.56,"quantity":5}]}]
Query
db.collection.aggregate([{$match:{userId:1}},{$unwind:"$orders"},{$group:{_id:null,totalPrice:{$sum:{"$multiply":["$orders.price","$orders.quantity"]}}}},{$project:{_id:0,totalPrice:1}}])