Database

db={"user":[{"_id":1,"name":"Tom"},{"_id":2,"name":"Alice"}],"transactions":[{"userId":1,"amount":100},{"userId":1,"amount":20},{"userId":2,"amount":40}]}

Query

db.user.aggregate([{"$lookup":{"from":"transactions","localField":"_id","foreignField":"userId","as":"transactions"}},{"$project":{"name":1,"total":{"$sum":"$transactions.amount"}}}])

Result