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.

Similar Reads

$addToSet Operator in MongoDB

The $addToSet operator in MongoDB is used to add a value to an array and if the value already exists in the array, then this operator will do nothing....

Syntax

The syntax to use the $addToSet Operator in MongoDB is:...

MongoDB $addToSet Operator Examples

In the following examples, we are working with:...

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....

Contact Us