MongoDB - Aggregate Sum
问题 I am attempting to calculate the total amount of money spent being tracked inside of our database. Each order document contains a field "total_price" I am attempting to use the following code: db.orders.aggregate({ $group: { _id: null, total: {$sum: "$total_price"} } }) Unfortunately, the only output I get is: { "result" : [ { "_id" : null, "total" : 0 } ], "ok" : 1 } But to verifiy there is actually numerical data stored, and just not being totaled: db.orders.find()[0].total_price this