Sunday, 18 June 2023

How to delete data by id in nodejs and mongodb API REST

 Today i will try to share information that is "How to delete data by id in nodejs and mongodb API REST".

Now lets see piece of code below :

exports.deleteActivityById =  async function(req, res, next){
 
  dy.findByIdAndDelete(req.body.id)
  .then((docs)=>{
     
    res.json(docs);
  })
  .catch((err)=>{
      console.log(err);
      res.status(401).json({ message: 'Something Wrong' });
  });
};


dy.findByIdAndDelete(req.body.id)

This is main code to delete data by id,

Hope this information can helping you, and any questions please leave a comment below thanks.


No comments:

Post a Comment