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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With