Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

Is there some procedure to rollback my last query mongo collection as I have deleted some documents in my last query.

The query is as follows :

 

db.foo.remove({ "name" : "some_x_name"}) 

2 Answers

0 votes
by (107k points)
edited by

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.

Do you want to be a full-stack developer? Enroll in this Full Stack Certification to get started with your journey.

0 votes
ago by (3.1k points)

Yes there is, In MongoDB, deleted documents can only be recovered if measures are not specifically done before their deletion. Here are some ways you can recover a deleted document: 

Backup and Restore: If you always back up your MongoDB database, then you can restore your MongoDB database from the most current backup. 

Oplog (if Replica Sets are set): If you have MongoDB configured as a replica set, you can restore deleted documents by replaying operations from the oplog. Use this method as fast as you can because the oplog only keeps so long. 

Use MongoDB Atlas Backup if you use MongoDB Atlas: Atlas maintains continuous backups so point-in-time restores can be done inside a defined retention window. 

Without either a backup nor a replica set's oplog, you cannot perform direct recovery. 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...