undo remove operation in mongodb
Asked Answered
A

4

10

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?

Autoroute answered 17/12, 2013 at 6:12 Comment(1)
You could also use findAndModify next time, as it returns the deleted object.Stylet
P
14

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.

Protractor answered 17/12, 2013 at 9:32 Comment(0)
O
2

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.

Ojibwa answered 17/12, 2013 at 9:11 Comment(0)
L
2

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

Lafontaine answered 18/10, 2022 at 10:11 Comment(0)
A
0

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
Astrogate answered 5/5, 2023 at 23:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.