That Error 100 — Why It Shows Up
You start MongoDB and see it crash with cannot recover, error code 100. This usually happens after a power loss, a hard shutdown, or a disk that ran out of space. The database can't read its own journal files or data files properly. I know how frustrating this is — I lost a dev database this way once and had to rebuild from a backup. Good news: most of the time you can fix it without losing data.
Quick Fix: Restart MongoDB Service (30 seconds)
This sounds dumb, but it works more often than you'd think. MongoDB might have had a temporary glitch or the journal file was in a weird state from a prior crash.
- Stop MongoDB — on Ubuntu/Debian:
sudo systemctl stop mongod. On Windows:net stop MongoDB. - Wait 5 seconds.
- Start it again:
sudo systemctl start mongodornet start MongoDB. - Check the logs:
tail -100 /var/log/mongodb/mongod.log. If you seerecovery completeand no error 100, you're good.
If it still crashes with error 100, move to the next fix.
Moderate Fix: Repair the Database (5 minutes)
This rebuilds the data files and journal. MongoDB's mongod --repair command checks every document and throws away damaged ones. You might lose a few records, but the database will start.
- Stop MongoDB completely.
- Locate your data directory. Default is
/var/lib/mongodbon Linux,C:\Program Files\MongoDB\Server\4.0\dataon Windows. - Run repair pointing to that path:
On Windows:mongod --dbpath /var/lib/mongodb --repairmongod --dbpath "C:\Program Files\MongoDB\Server\4.0\data" --repair - Wait for it to finish — it can take 10–15 minutes for a large database. The output will say
repair doneorcompleted successfully. - Start MongoDB normally:
sudo systemctl start mongod. - Check if error 100 is gone. If not, try the next step.
Advanced Fix: Restore from Backup (15+ minutes)
This is the nuclear option. If repair fails or you see cannot recover even after repair, the data files are too far gone. I've seen this when the disk had bad sectors or the journal had inconsistent writes.
- Stop MongoDB if it's running.
- Move the corrupted data directory to a safe place:
sudo mv /var/lib/mongodb /var/lib/mongodb_corrupted - Create a fresh data directory:
sudo mkdir -p /var/lib/mongodb sudo chown mongodb:mongodb /var/lib/mongodb - Start MongoDB — it should start clean now. Check with
sudo systemctl status mongod. - Restore your latest backup. If you used
mongodump, run:mongorestore /path/to/backup/folder - If you don't have a backup, you're out of luck — that's why I always set up automated backups after this happened to me.
Preventing Error 100 in the Future
- Always shut down MongoDB cleanly with
db.shutdownServer()from the mongo shell. - Use a UPS for your server — power loss is the #1 cause of this error.
- Monitor disk space. MongoDB needs free space to write journal files. Set up alerts at 80% usage.
- Enable journaling — it's on by default in MongoDB 3.2+, but double-check your config file has
storage.journal.enabled: true.
If none of these fixes work, post your MongoDB version (check with mongod --version) and the full error log. I'll help you dig deeper.