Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
        }
    });
)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #append #data #field #mongoose #model
ADD COMMENT
Topic
Name
6+5 =