I am trying to calculate the total amount of money spent, tracked inside our database. Each order document contains the field "total_price"
I am trying 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 for verification, digital data is really stored and simply not summed up: db.orders.find()[0].total_price this leads to 8.99
Any help would be greatly appreciated. I have very little experience using MongoDB. I just covered the basics at this point.
Thanks in advance.
source share