Database
db={"categories":[{_id:1,name:"Category 1"}],"products":[{_id:1,name:"Product 1",price:20}],"prodcutcategories":[{product:1,category:1}],"orders":[{product:1,price:20,quantity:10}]}
Query
db.orders.aggregate([{$lookup:{from:"products",localField:"product",foreignField:"_id",as:"p"}},{$lookup:{from:"prodcutcategories",localField:"p._id",foreignField:"product",as:"pc"}},{$lookup:{from:"categories",localField:"pc.category",foreignField:"_id",as:"cat"}},{$unwind:"$cat"},{$unwind:"$p"},{$group:{_id:"$cat.name",totalPrice:{$sum:"$price"},qty:{$sum:"$quantity"},totalSold:{$sum:1}}}])