Thursday, 18 May 2017

How can Mongoose "delete" non-existing documents?

Code:

function deleteItem(req, res) {
    Goods.findByIdAndRemove(req.params.id, (err) => {
    if (err) {
      res.send({
        success: false,
        error: err
      });
    } else {
      res.send({
        success: true,
        item: req.params.id
      });
    }
  })
}

If I pass an _id of just deleted document - Mongoose successfully "deletes" it.
If I pass an _id of never existed document, like 591dad9a1583ea0d1065d633 - it also "deletes" it.

Error throws only if pass trash like a34pnv530eargdzbs.

Could somebody tell me, what's going on, please ? :)



via Seva

No comments:

Post a Comment