Answers for "mongoose find one and update push to array"

1

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
3

add items to a list in a document monoose

const {name , id} = req.body
    Category.update(
        {_id: id}, 
        {$push: {items: {"name": name}}},{new: true, upsert: true }).exec();
        res.sendStatus(200)
Posted by: Guest on August-07-2020
0

how to append data to a field in mongoose model

//mongoose appending data

var objFriends = { fname:"fname",lname:"lname",surname:"surname" };
Friend.findOneAndUpdate(
   { _id: req.body.id }, 
   { $push: { friends: objFriends  } },
  function (error, success) {
        if (error) {
            console.log(error);
        } else {
            console.log(success);
        }
    });
)
Posted by: Guest on August-21-2020

Code answers related to "mongoose find one and update push to array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language