KeyTakeAways About $addToSet Operator
- $addToSet Operator inserts a new value to an array field in the document.
- This operator does not insert duplicate items in the array and does not affect already present duplicate items. Here, the order of the values does not matter.
- If the specified field in the
$addToSet
the operator is not present in the document, then this operator creates an array field in the document with values or items.- Is the specified value is an array in the
$addToSet
operator, then this operator will append the whole array as a single item. Or if you want to add items separately in the array, then use $each modifier.
MongoDB $addToSet Operator
MongoDB $addToSet Operator adds a value to an array field in the document.
Contact Us