How to Restore MongoDB Database After Having Deleted DB Files From Directory I'm running MongoDB 2.6 on Ubuntu 14.04 and I accidentally deleted db file in /var/lib/mongodb. 

I cannot restart the MongoDB instance:

mongo: error SEVERE: unable to open file number 5. 


If I purge and re-install will I be able to restore the data? Any help is appreciated.
3-rd Party Tool

You might want to consider recovering the files using the PhotoRec tool.

Reference: PhotoRec Homepage


  PhotoRec is file data recovery software designed to recover lost files including video, documents and archives from hard disks, CD-ROMs, and lost pictures (thus the Photo Recovery name) from digital camera memory. PhotoRec ignores the file system and goes after the underlying data, so it will still work even if your media's file system has been severely damaged or reformatted.


Prerequisites

First of all you will have to ensure that no more writes are performed against the disk in your Ubuntu system, otherwise you might be overwriting the deleted files.

Step by Step Guide

Then you can consider following the step by step instructions provided on their website.


  This Recovery example guides you through PhotoRec step by step to recover deleted files or lost data from a reformatted partition or corrupted file system. For lost/deleted partitions or deleted files from a FAT or NTFS file system, try TestDisk first - it's usually faster and TestDisk can retrieved the original file names. Translations of this PhotoRec manual to other languages are welcome.
  
  ...
  
  Under Unix/Linux/BSD, you need to be root to run PhotoRec (ie. sudo testdisk-6.13/photorec_static)


Reference: PhotoRec Step By Step

Short Quick Version


Start PhotoRec from a USB medium or other disk than where your database files reside.  
Select disk.
Hit Proceed
Select partition.
Hit either
 a. Search
 b. Options
 c. File Opt
 d. Quit (well not really, unless you are unsure)  
After hitting Search the tool will try and to determine the file system. If you know your filesystem type, select the appropriate one.
Select either the Free space option or the Whole option depending on your requirements.
Select where your recovered files should be copied to. 


  Tip: Copying to another drive (USB, eSata, other disk than where the database resides) will increase the probability of not destroying the file you are trying to recover.

Hope that the files are displayed as recovered in the summary.


The files on your disk might have already been overwritten and unrecoverable. But good luck anyway.


  Disclaimer
  I am in not way affiliated with PhotoRec or any of its employees.
  No guarantee given that the provided solution will result in recoverable files. You are trying this procedure at your own risk.




Future Considerations


Implement a backup solution (script/3-rd party tool/...)
Test your backup solution
Test a restore of database backup which were created with the backup solution


Reference: MongoDB Backup Methods (MongoDB Site)