Complete the code to sum the values of the "score" field in the aggregation.
db.scores.aggregate([{ $group: { _id: null, totalScore: { $sum: "$"[1] } } }])The $sum accumulator sums the values of the specified field. Here, we sum the "score" field.
Complete the code to sum the values of the "quantity" field grouped by "category".
db.products.aggregate([{ $group: { _id: "$"[1], totalQuantity: { $sum: "$quantity" } } }])The _id field in $group specifies the grouping key. Here, we group by "category" to sum quantities per category.
Fix the error in the aggregation pipeline to correctly sum the "amount" field.
db.transactions.aggregate([{ $group: { _id: null, totalAmount: { $sum: [1] } } }])The $sum accumulator requires the field to be prefixed with a $ sign without quotes, like $amount.
Fill both blanks to sum the "price" field grouped by "brand".
db.items.aggregate([{ $group: { _id: "$"[1], totalPrice: { $sum: "$"[2] } } }])Group by the "brand" field and sum the "price" field values.
Fill all three blanks to sum the "score" field grouped by uppercase "player" names.
db.games.aggregate([{ $group: { _id: { [1]: { $toUpper: "$"[2] } }, totalScore: { $sum: "$"[3] } } }])Use { $toUpper: "$player" } to group by uppercase player names and sum their scores.