1const {name , id} = req.body
2 Category.update(
3 {_id: id},
4 {$push: {items: {"name": name}}},{new: true, upsert: true }).exec();
5 res.sendStatus(200)
1exports.addFriend = function (req, res, next)
2{
3var friend = {"firstName": req.body.fName, "lastName": req.body.lName};
4Users.findOneAndUpdate({name: req.user.name}, {$push: {friends: friend}});
5};
1
2//mongoose appending data
3
4var objFriends = { fname:"fname",lname:"lname",surname:"surname" };
5Friend.findOneAndUpdate(
6 { _id: req.body.id },
7 { $push: { friends: objFriends } },
8 function (error, success) {
9 if (error) {
10 console.log(error);
11 } else {
12 console.log(success);
13 }
14 });
15)