Database

[{order_id:123,customer_id:1,order_items:[{product_id:1,price:2},{product_id:4,price:8},{product_id:1,price:2}]},{order_id:124,customer_id:5,order_items:[{product_id:5,price:7},{product_id:4,price:8}]}]

Query

db.collection.aggregate([{$unwind:{path:"$order_items",preserveNullAndEmptyArrays:true}},{$group:{_id:"$order_items.product_id",tot_price:{$sum:"$order_items.price"}}},{$project:{_id:0,product_id:"$_id",tot_price:1}}])

Result