Home Ask Login Register

Developers Planet

Your answer is one click away!

kamaal 2 weeks ago

Unable to delete data from mongoDB

Im using POSTMAN to delete contact using id and it returns
{
   "n": 0,
   "ok": 1
}

This is my delete code so far

router.delete('/contact/:id', (req, res, next) => {
  contact.remove({ _id: new objectId(req.params._id) }, function(err, result) {
    if (err) {
      res.json(err);
    } else {
      res.json(result);
    }
  });
});

Answers


Vikash.777 2 weeks ago

Try this..

router.delete('/contact/:id', (req, res, next) => {
  contact.deleteOne({ _id: new objectId(req.params._id) }, function(err, result) {
    if (err) {
      res.json(err);
    } else {
      res.json(result);
    }
  });
});

Post Status

Asked in 2 weeks ago
Viewed 2,588 times
Voted 10
Answered 1 times

Search




Leave an answer


Quote of the day: live life