Answers for "add in to array mongoose"

1

how to append data to a field in mongoose model

exports.addFriend = function (req, res, next)
{
var friend = {"firstName": req.body.fName, "lastName": req.body.lName};
Users.findOneAndUpdate({name: req.user.name}, {$push: {friends: friend}});
};
Posted by: Guest on August-21-2020
1

add in to array mongoose

// With { $push: { field: element } }

// Example:
const elementToPush = { a: 1, b: 2 };
const body = { $push: { arrayField: elementToPush } };
model.patch(id, body);
Posted by: Guest on November-19-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
3

mongodb push to arry in update

db.collection.update({_id:xx}, {$pop:{letters : -1}})
Posted by: Guest on March-22-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language