Some collections were accidentally dropped from mongodb. Although the collections do not exist, in the dbpath there are 6GB of dbname.0, dbname.1,... and dbname.ns

We tried to run mongod --repair but instead of recovering the files it deleted them.

Is there a way to recover these data? maybe partially?

We are using standalone mongodb.



We tried to run mongod --repair but instead of recovering the files it deleted them.

Repair and backup processes will (by design) ignore deleted data. Based on the filenames referenced in your question, you are using the MMAP storage engine. When a record is deleted in MMAP the first several bytes of the record are overwritten and the preallocated storage space is marked as available for re-use on the free list. There is a possibility you could write a custom script to try to recover useful bytes from deleted records, but there is no supported "undo" process for doing so.

Hopefully you took a backup of your data files before running --repair. Repairing MMAP data files results in a compete rebuild of your data files and would free up preallocated space used by deleted collections and documents. In any case where you are trying to recover or repair database files from a standalone MongoDB deployment, stopping your MongoDB instance and taking a file copy backup of your data files is a recommended starting point.

Is there a way to recover these data? maybe partially?

Your best option would be to restore from your most recent MongoDB backup.

In a standalone MMAP deployment without backups, the only other possibility would be writing custom data recovery scripts to try to identify and salvage deleted documents. This involves some significant guesswork and manual effort to clean up data. Deleted records will be missing some essential information such as the size of the associated BSON document, and there may be variations in internal storage depending on the provenance of your data (for example, if all data was created in a specific version of MongoDB versus data files that have been upgraded through successive major releases).

See StackOverflow: Is there any way to recover deleted documents? for some possible approaches.


Maybe, because you are using MMAPv1 and with older version (<3.0) mongodump you can use --dbPath parameter to connect directly to those files. Dump data to the file and then import it back to your current database.

This is in theory.

Have you tried to create that DB again and then copy those file (except .ns, just .) over new ones?

  • Unfortunately neither of these approaches will be helpful. Deleted records are intentionally ignored by backup & repair tools; copying database files with deleted data also does not have the side effect of undeleting data. In general, mixing data files from another deployment is highly likely to lead to further complications :).
    – Stennie
    Oct 29 '17 at 2:07

Restore dropped database using mongoimport from delayed node

Then roll back all operations on primary by keeping it in standalone ,

Abort all operations happening in while roll back by locking that database ,and generating operation failed, try after 24 hours on application level

After roll back successfully done , u can Start replication , on primary,

However there is performance loss of 24 hours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.