Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

findByIdAndUpdate in express

//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,
    });
  }
};
 
PREVIOUS NEXT
Tagged: #findByIdAndUpdate #express
ADD COMMENT
Topic
Name
1+7 =