$addToSet operator do in MongoDB?$addToSet adds a value to an array only if the value is not already present, ensuring unique elements.
$addToSet different from $push in MongoDB?$push adds values to an array regardless of duplicates, while $addToSet adds only if the value is not already in the array.
"apple" uniquely to the fruits array.{ $addToSet: { fruits: "apple" } }$addToSet add multiple unique values at once? If yes, how?Yes, by using $each inside $addToSet to add multiple unique values.
{ $addToSet: { fruits: { $each: ["apple", "banana"] } } }$addToSet on a field that is not an array?If the field does not exist, MongoDB creates an array with the value. If the field exists and holds a non-array value, the update operation fails and MongoDB returns an error.
$addToSet ensure when adding elements to an array?$addToSet adds elements only if they are not already present, preventing duplicates.
$push adds elements to an array regardless of duplicates.
$addToSet?$each allows adding multiple unique values at once inside $addToSet.
$addToSet do?$addToSet creates the field as an array containing the value if it does not exist.
$addToSet?Option B correctly uses $each with an array inside $addToSet to add multiple unique values.
$addToSet helps maintain unique elements in a MongoDB array.$addToSet and $push when updating arrays in MongoDB.