Add multiple values using $addToSet Mongo operator

From the docs for $addToSet:

If the value is an array, $addToSet appends the whole array as a
single element. To add each element of the value separately, use
$addToSet with the $each modifier. See Modifiers for details.

So you should use this instead:

db.c.update({}, {$addToSet: {a: {$each: [2, 4]}}})

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)