Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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,
    });
  }
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #findByIdAndUpdate #express
ADD COMMENT
Topic
Name
9+1 =