Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undo remove operation in mongodb

I run by mistake a db.collection_name.remove({condition:'true'}) from console and delete object I didn't plan to delete, can I recover them some how?

I db is on mongohq, if it can helps?

like image 457
Alon Gutman Avatar asked Dec 17 '13 06:12

Alon Gutman


People also ask

How do I undo a delete in MongoDB?

No, you can't rollback your queries as there is no such thing as a rollback in MongoDB. But you can use oplog (operations log) as this is a distinctive capped collection that maintains a rolling record of all processes/operations that you have used to modify the data that is stored inside your MongoDB databases.

Can we retrieve deleted data in MongoDB?

The most reliable way to recover deleted data is to use a Supported Backup Method with continuous backup (for example, agent-based backup like MongoDB Ops Manager) or an acceptable schedule for your recovery scenarios. Ops Manager also includes a Queryable backup feature to help with selective recovery of data.

What is remove in MongoDB?

The remove() Method MongoDB's remove() method is used to remove a document from the collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag. deletion criteria − (Optional) deletion criteria according to documents will be removed.


1 Answers

It's too late now, but to prevent this from happening again, you can add a member to your replset with priority 0 and slaveDelay set to an hour or so, so that it will be (at least) an hour behind the primary. This member could serve as an oops-I-probably-shouldn't-have-hit-enter-quite-yet recovery.

like image 109
Mzzl Avatar answered Oct 25 '22 23:10

Mzzl