Model.findByIdAndUpdate(id, updateObj, {new: true}, function(err, model) {...
var user_id = '5eb985d440bd2155e4d788e2';
User.findByIdAndUpdate(user_id, { name: 'Gourav' },
function (err, docs) {
if (err){
console.log(err)
}
else{
console.log("Updated User : ", docs);
}
});
//controllers/tourController.js
const Tour = require('./../models/tourModel');
exports.updateTour = async (req, res) => {
try {
const tour = await Tour.findByIdAndUpdate(req.params.id, req.body, {
new: true,
});
res.status(200).json({
status: 'success',
data: {
tour: 'Updated tour ',
},
});
} catch (error) {
res.status(404).json({
status: 'Error',
message: error,
});
}
};