Complete the code to calculate the total number of documents in the collection.
db.sales.aggregate([{ $group: { _id: null, total: { $[1]: 1 } } }])The $sum operator adds values together. Here, it counts each document by adding 1 for each.
Complete the code to find the average price of all products.
db.products.aggregate([{ $group: { _id: null, averagePrice: { $[1]: "$price" } } }])The $avg operator calculates the average of the specified field values.
Fix the error in the aggregation to find the maximum score.
db.scores.aggregate([{ $group: { _id: null, maxScore: { $[1]: "$score" } } }])The correct operator to find the maximum value is $max. Other options are invalid.
Fill both blanks to calculate the total sales and average quantity.
db.orders.aggregate([{ $group: { _id: "$product", totalSales: { $[1]: "$amount" }, averageQty: { $[2]: "$quantity" } } }])$sum adds all amounts for total sales, and $avg calculates the average quantity.
Fill all three blanks to group by category, count items, and find max price.
db.items.aggregate([{ $group: { _id: "$category", count: { $[1]: 1 }, maxPrice: { $[2]: "$price" }, minPrice: { $[3]: "$price" } } }])$sum counts items by adding 1 each, $max finds the highest price, and $min finds the lowest price.