I am trying to remove a document from a mongoDB collection by finding the document in the collection using an id. Below is a snippet of my code and it says that the note was successfully deleted but when I go back to where all the notes are displayed, the note that was supposedly deleted is still there.
router.post('/delete', function(req, res) {
notesCollection.remove(prevID, function(err, records){
if(err){
res.render("deleteFail.jade");
}
else{
res.render("deleteSuccess.jade");
}
});
});
Where prevID is the _id of the note currently trying to be deleted. Any help is greatly appreciated! Thanks
Are you using mongoose? I am pretty certain the first argument has to be a query object, eg { _id: prevId }
and not just the id directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.