The following is my code snap, I've come across the solution of using {new: true} as an additional argument, but I'm not able to use it with .then() function. I need some way to retreive the updated value.
router.post('/profile/:userId', checkAuth, (req, res, next) => {
Profile.findOneAndUpdate({
name: req.body.name,
age: req.body.age,
user: req.body.user,
education: req.body.education,
location: req.body.location,
phone: req.body.phone
}).then(result => {
console.log(result);
res.status(201).json(result);
}).catch(err => {
console.log(err);
res.status(500).json({error: err});
});
});