Skip to content Skip to sidebar Skip to footer

How To Update Existing User Data In A Node.js And MongoDB App With Ejs Post Form?

I am extremely new to javascript and found Brad Traversy's video Node.js with Passport Authentication and followed his video to a t. It worked for me, but then I wanted to add more

Solution 1:

in your requiring User model do it like this

const User=require('../models/User');

then

function updateRecord(req, res) {
User.findOne({_id:req.body.id},(err,doc)=>{
 //this will give you the document what you want to update.. then 
doc.name = req.body.name; //so on and so forth

// then save that document
doc.save(callback);

});

}

Post a Comment for "How To Update Existing User Data In A Node.js And MongoDB App With Ejs Post Form?"