Answers for "mongoose find one and update push into aray"

0

append to array mongoose updateone

/*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 } }
);
Posted by: Guest on August-25-2021
0

mongoose update array push multiple

Kitten.update(
  { name: 'fluffy'},
  {
    $push: {
      values: {
        $each: [2, 3]
      }
    }
  }
)
  .then(result => {
  	console.log(result)
  })
  .catch(err => {
    console.error(err)
  })
Posted by: Guest on March-23-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language