📜  追加到数组 mongoose updateone - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:23.391000             🧑  作者: Mango

代码示例1
/*Another way to push items into array using Mongoose is-
  $addToSet, if you want only unique items to be pushed into 
  array. $push operator simply adds the object to array whether
  or not the object is already present, while $addToSet does that
  only if the object is not present in the array so as not to
  incorporate duplicacy.*/

PersonModel.update(
  { _id: person._id }, 
  { $addToSet: { friends: friend } }
);