Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to use $addToSet to add unique values to the array.
MongoDB
{ $group: { _id: "$category", items: { [1]: "$item" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push instead of $addToSet, which allows duplicates.
Using $sum or $avg which are for numeric calculations, not arrays.
✗ Incorrect
The $addToSet accumulator adds unique values to an array, avoiding duplicates.
2fill in blank
mediumComplete the aggregation stage to group by "type" and collect unique "tags" using $addToSet.
MongoDB
{ $group: { _id: "$type", uniqueTags: { [1]: "$tags" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push which does not remove duplicates.
Using $first or $max which return single values, not arrays.
✗ Incorrect
$addToSet collects unique values from the "tags" field into an array.
3fill in blank
hardFix the error in the aggregation pipeline to correctly use $addToSet for unique "colors".
MongoDB
{ $group: { _id: "$brand", colors: { [1]: "$colors" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push instead of $addToSet.
Using numeric accumulators like $sum or $avg for arrays.
✗ Incorrect
Only $addToSet correctly accumulates unique values in an array.
4fill in blank
hardFill both blanks to group by "department" and collect unique "employees" using $addToSet.
MongoDB
{ $group: { _id: "$department", [1]: { [2]: "$employee" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push instead of $addToSet.
Using field names like "members" without matching the code.
✗ Incorrect
The field name can be any valid name like "staff"; $addToSet collects unique employees.
5fill in blank
hardFill both blanks to group by "category", collect unique "products" with $addToSet, and name the array "uniqueProducts".
MongoDB
{ $group: { _id: "$category", [1]: { [2]: "$product" } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push which allows duplicates.
Confusing field names or accumulator names.
✗ Incorrect
The field name is "uniqueProducts", the accumulator is $addToSet, and "items" is a distractor option not used here.