Complete the code to calculate the average score from the scores collection.
db.scores.aggregate([{ $group: { _id: null, averageScore: { $[1]: "$score" } } }])The $avg accumulator calculates the average value of the specified field.
Complete the code to calculate the average price for each product category.
db.products.aggregate([{ $group: { _id: "$category", avgPrice: { $[1]: "$price" } } }])The $avg accumulator calculates the average price per category.
Fix the error in the aggregation to correctly compute the average rating.
db.reviews.aggregate([{ $group: { _id: "$productId", averageRating: { $[1]: "$rating" } } }])The field name must be prefixed with a dollar sign inside $avg. Use "$rating" to refer to the field.
Fill both blanks to calculate the average age of users grouped by city.
db.users.aggregate([{ $group: { _id: "$city", [1]: { $avg: [2] } } }])The first blank is the name of the output field, here averageAge. The second blank is the field to average, which must be "$age" with a dollar sign.
Fill all three blanks to compute the average score for each team and label the output field as 'teamAverage'.
db.scores.aggregate([{ $group: { _id: [1], [2]: { $[3]: "$score" } } }])The group key is the team field, so "$team". The output field is named teamAverage. The accumulator is $avg to calculate the average.