Database
db={"Product":[{"_id":1,"name":"A"},{"_id":2,"name":"B"},],"Sales":[{"_id":1,"name":"A",qty:1},{"_id":2,"name":"A",qty:1},{"_id":3,"name":"B",qty:1},],"Purchases":[{"_id":1,"name":"A",qty:5},{"_id":2,"name":"A",qty:10},{"_id":3,"name":"B",qty:50},]}
Query
db.Product.aggregate([{$lookup:{from:"Purchases",localField:"name",foreignField:"name",as:"Purchases"}},{$lookup:{from:"Sales",localField:"name",foreignField:"name",as:"Sales"}},{$project:{"name":1,currentQty:{$subtract:[{$sum:"$Purchases.qty"},{$sum:"$Sales.qty"}]}}}])