$addToSet¶
-
$addToSet¶ The
$addToSetoperator adds a value to an array only if the value is not in the array already. If the value is in the array,$addToSetreturns without modifying the array. Consider the following example:Here,
$addToSetappendsvalue1to the array stored infield, only ifvalue1is not already a member of this array.Note
$addToSetonly ensures that there are no duplicate items added to the set and does not affect existing duplicate elements.$addToSetdoes not guarantee a particular ordering of elements in the modified set.-
:update:`$each`
See also
-