Is it possible to get the document that was removed from MongoDB?
result = db.things.remove({_id: id})
// is there a result.removedObjects?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is possible, but it requires a different command. You are looking for the
findAndModifycommand.If you set the options to
{query: ..., remove: true, new: false}, you will delete a single document and return the removed document.Some notes:
newis a keyword in many languages, ensure that you are wrapping the text of the flag correctly.findAndModifywill only work with a single document. This is fine for deleting_idbut not good for ranged removes.