The $set
operator will, of course, change the whole data of the array
property.
If you want to just push, use $push
(which pushes one item at once) or $pushAll
(which pushes all items of an array).
If you want to push without repeating an item, use $addToSet
.
Note: If you're on MongoDB 2.4 (the latest version), use $push
with the new $each
modifier. This deprecates usage of $pushAll
(this applies to $addToSet
, too)
Docs: