For some collection with a field { wins: Number }, how could I use MongoDB Aggregation Framework to get the total number of wins across all documents in a collection?
Example:
If I have 3 documents with wins: 5, wins: 8, wins: 12 respectively, how could I use MongoDB Aggregation Framework to return the total number, i.e. total: 25.
$groupoperation as shown in the docs.db.characters.aggregate([{$group:{_id:'id',wins:{$sum:1}}}]);but without any luck. It returns how manywinsfields i have instead of values from the wins.db.characters.aggregate( [ { $group: { _id: null, total: { $sum: "$wins" } } } ] )