When Mongo closes incorrectly, (due to things like crashes, hard reboots, etc…), it leaves behind a non-zero byte mongod.lock
file. The presence of this file indicates that Mongo wasn’t cleaned up correctly and will prevent Mongo from starting normally.
In a Meteor project, meteor
will fail with the following messages if it detects that Mongo was not correctly shut down:
=> Started proxy.
Unexpected mongo exit code 100. Restarting.
Unexpected mongo exit code 100. Restarting.
Unexpected mongo exit code 100. Restarting.
Can't start Mongo server.
MongoDB had an unspecified uncaught exception.
This can be caused by MongoDB being unable to write to a local database.
Check that you have permissions to write to .meteor/local. MongoDB does
not support filesystems like NFS that do not allow file locking.
To fix this, two things need to happen. First, remove the lock file:
% rm .meteor/local/db/mongod.lock
Not that the lock file is deleted, Meteor should start without any complaints from Mongo. To be safe, Mongo’s repair routine should be run on your Meteor database. Normally, this is done using a mongod
command (mongod --repair
), but since Meteor doesn’t use mongod
, we need to kick off the repair from within the Mongo shell:
% meteor mongo
> db.repairDatabase()
{ “ok” : 1}
That’s it! You can read more about how to recover data after an unexpected shutdown in the Mongo docs.