Thứ Ba, 10 tháng 9, 2024

[ MongoDB ] What to do if you accidentally drop a MongoDB table?

In fact, many people when encountering this situation think that it is impossible to save MongoDB data. And very few people share about this case. This is a very real situation and has many difficulties when faced. If the database is Oracle, we can easily do it. However, what about MongoDB? The answer is yes. However, the way to save data will be more complicated. In this article, I will share with you a method that can save data when deleting or dropping the wrong table. A useful method for those who accidentally impact the database Step 1: Immediately backup oplog after detecting the wrong data deletion behavior The command is as follows: mongodump -u username --authenticationDatabase admin -p password -d local -c oplog.rs --out /backup/mongo Step 2: Determine the timestamp on the oplog.rs table to restore the point in time before the drop time db.getCollection("oplog.rs").find({"o.drop" : "collection_name"}) Step 3: Recover the point in time of the dropped data to save the data mongorestore --port 27017 -u username -p password --authenticationDatabase admin --oplogReplay --oplogLimit=1725939063:1 /backup/mongo/local/oplog.rs.bson

Share This!


Không có nhận xét nào:

Đăng nhận xét