Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover a dropped MongoDB database?

If somebody accidentally dropped a MongoDB database but executing db.dropDatabase(), how can he recover the database?

Dropping a database in MongoDB is simple, and the command db.dropDatabase() won't erase all the data on it but marks it as to be deleted, so the size of the database would not change after using the drop command, which I think there should be some way to remove the to-be-deleted marker. Can some one point me how?

like image 373
imcoddy Avatar asked Jul 08 '11 02:07

imcoddy


1 Answers

I tried to reproduce what you had done. I killed a database using db.dropDatabase() after I had backed it up :-) The db name was 'gacheater'. Before dropping mongodb folder contained 3 files (the db is non-empty):

  • gacheater.ns
  • gacheater.1
  • gacheater.2

after dropping these files disappeared. Therefore I think mongodb really removes your data.

So the only choice you have is to try to restore files from the filesystem

PS: MacOS 10.5, MongoDB 1.8.2

like image 62
Maksym Polshcha Avatar answered Sep 25 '22 00:09

Maksym Polshcha