Complete the code to use $push to add values to an array in aggregation.
db.collection.aggregate([{ $group: { _id: "$category", items: { [1]: "$item" } } }])The $push accumulator adds values to an array during aggregation.
Complete the code to group documents by "type" and push "name" into an array.
db.products.aggregate([{ $group: { _id: "$type", names: { [1]: "$name" } } }])$push collects all "name" values into an array for each "type" group.
Fix the error in the aggregation pipeline to correctly push "score" values into an array.
db.scores.aggregate([{ $group: { _id: "$player", scores: { [1]: "$score" } } }])$push correctly accumulates all "score" values into an array per player.
Fill both blanks to group by "department" and push "employee" names into an array.
db.employees.aggregate([{ $group: { _id: [1], staff: { [2]: "$employee" } } }])The _id must be the field to group by, here "$department", and $push collects employee names.
Fill all three blanks to group by "category", push "product" names, and filter only categories with more than 2 products.
db.products.aggregate([
{ $group: { _id: [1], products: { [2]: "$product" } } },
{ $match: { $expr: { $gt: [ { $[3]: "$products" }, 2 ] } } }
])Group by "$category", use $push to collect products, and filter with size to check array length.