Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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}});
};
Comment

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);
        }
    });
)
Comment

PREVIOUS NEXT
Code Example
Javascript :: make object to array javascript 
Javascript :: javascript select multiple values 
Javascript :: remove repetition 2d array javascript 
Javascript :: javascript slice array 
Javascript :: mongoose countdocuments 
Javascript :: what is vanilla javascript 
Javascript :: add one file to another in ejs 
Javascript :: foreach index 
Javascript :: javascript append array to array 
Javascript :: react 18 render 
Javascript :: all   to space from string javascript 
Javascript :: string.contains javascript 
Javascript :: text overflow ellipsis two lines react native 
Javascript :: why does my form reload the page? html js 
Javascript :: Redirect to any page after 5 seconds in Javascript 
Javascript :: moment get timestamp 
Javascript :: graphql request with jquery ajax 
Javascript :: falsy values javascript 
Javascript :: open folder node js 
Javascript :: get background image url jquery 
Javascript :: window widht jquery 
Javascript :: how to get variable value outside function in javascript 
Javascript :: wait until something happens javascript 
Javascript :: hcaptcha bypass 
Javascript :: jquery fadeout to fadein 
Javascript :: check array values equal js 
Javascript :: check if a date is more than 18 years javascript 
Javascript :: angularjs dropdown 
Javascript :: how to validate email in node js 
Javascript :: check if a word exists in dictionary javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =