append to array mongoose updateone

Solutions on MaxInterview for append to array mongoose updateone by the best coders in the world

showing results for - "append to array mongoose updateone"
Agustín
25 Mar 2020
1/*Another way to push items into array using Mongoose is-
2  $addToSet, if you want only unique items to be pushed into 
3  array. $push operator simply adds the object to array whether
4  or not the object is already present, while $addToSet does that
5  only if the object is not present in the array so as not to
6  incorporate duplicacy.*/
7
8PersonModel.update(
9  { _id: person._id }, 
10  { $addToSet: { friends: friend } }
11);
12