undo remove operation in mongodb

24.3k views Asked by At

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?

4

There are 4 answers

0
chk On

MongoDB itself has no mechanismn to undo deletions. As your DB is hosted in the cloud, you will probably also not be able to do any OS-based recovery (such as Time Machine on Mac) even though I've never used MongoHQ so far to know for sure.

As you can read in the MongoHQ Doc a (free) recovery is not possible, you are rather encouraged to back up the data yourself.

0
Mzzl On

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.

0
Khizar Laique On

if You've mongorestore working or installed, You can restore bson file by importing .bson

mongorestore -d db_name -c collection_name /path/file.bson
0
MasterPiece On

If you're using NoSqlBooster, you could find the deleted document if you made a find operation before deleting it.

You can click on Show Log at the right bottom corner, and see the last queries including their results. Just look for the query with the relevant result and then double click on its "result" column. Now you can just copy the relevant document and insert it again.

enter image description here