Reputation: 7123
I have id printing in controller from client now i want to delete this document from mongodb with below code is not showing any error but not even deleting document from collection , How can i delete document using _id
?
controller.js
var Diagram = {
remove: function(id, res) {
console.log('deletecontroller', id);
diagram.remove({
_id: id
});
}
}
module.exports = Diagram;
Upvotes: 1
Views: 1697
Reputation: 23642
I am not sure whether diagram
is your model here, try with your Model, because i don't see you are getting a document via find or findOne
method on which you can apply remove
method.
Model.remove({ _id: id}, function(err){});
Or you can also find and remove:
Model.findOne({_id: id}, function (error, daigram){
daigram.remove();
});
You can also use the latest version:
MyModel.findOneAndRemove({_id: id}, function(err){...});
Upvotes: 2