$addToSet

The `$addToSet` operator adds a value to an array only if the value is not already present in the array.

Syntax

{ $addToSet: { field: <value> } }

Parameters

fieldstringrequired

The field to update.

<value>stringrequired

The value to add to the array if it doesn't already exist.