node.js - Mongoose removes too many from ID -
i may misunderstanding something, on client have request sent server. like:
$.post("/resources/remove", {"id": 52024e25b26d39f931000003})
on server have
resource.remove({_id: request.body.id})
the "id" correct , using resource.find
same arguments returns record want remove. however, when run removes all resource
records. return value of exec(function (err, returnvalue)
number of resource
records there, removing of them. using remove.(request.body.id)
same thing.
do need else make sure record corresponding _id
removed? if entry invalid why removing all records?
try using resource.findoneandremove
reference
i've never used use , works me
postmodel.findone({_id: id}, function (err, result) { if (err) { throw err; } if (result) { postmodel.remove({_id: id}, function (err, result) { if (err) { throw err; } res.json(200, result); }); } });
Comments
Post a Comment