Complete the code to add a unique value to the 'tags' array using $addToSet.
db.collection.updateOne({ _id: 1 }, { $[1]: { tags: "mongodb" } })The $addToSet operator adds a value to an array only if it does not already exist, ensuring uniqueness.
Complete the code to add multiple unique values to the 'tags' array using $addToSet with $each.
db.collection.updateOne({ _id: 2 }, { $addToSet: { tags: { $[1]: ["nodejs", "database"] } } })The $each modifier allows adding multiple values uniquely with $addToSet.
Fix the error in the update command to correctly add a unique value to the 'categories' array.
db.collection.updateOne({ _id: 3 }, { $[1]: { categories: "tech" } })To add a unique value to an array, use $addToSet. Using $push adds duplicates.
Fill both blanks to add multiple unique tags to the 'labels' array.
db.collection.updateOne({ _id: 4 }, { $[1]: { labels: { $[2]: ["urgent", "review"] } } })Use $addToSet with $each to add multiple unique values to an array.
Fill all three blanks to add a unique uppercase tag to the 'tags' array using an aggregation pipeline update.
db.collection.updateOne({ _id: 5 }, [ { $[1]: { [2]: { $toUpper: "[3]" } } } ])In an aggregation pipeline update stage, use $addToSet (BLANK_1) on the tags field (BLANK_2) with the uppercase expression on urgent (BLANK_3) to add a unique uppercase tag.