When mongod Won't Start On OS X
mongod can be fickle. This morning I logged into my Mac to find that my applications couldn’t create a connection to the database, and I quickly discovered that my launchctl mongod daemon had crashed. My system.log was filled with messages like this one
Feb 21 10:44:57 alec com.apple.launchd (org.mongodb.mongod): Exited with exit code: 100 Feb 21 10:44:57 alec com.apple.launchd (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
and my mongodb log file had messages like
************** old lock file: /usr/local/mongodb_data/mongod.lock. probably means unclean shutdown recommend removing file and running --repair see: http://dochub.mongodb.org/core/repair for more information *************
Soemthing is definitely wrong.
So the first thing to do is try to repair your databases. Unload the launchctl daemon with
sudo launchctl unload -w /Library/LaunchDaemons/org.mongodb.mongod.plist
/Library/LaunchDaemons/org.mongodb.mongod.plist with the path to your launchctl plist file). Delete the lock file, wherever your data is:
Then run (NOT as sudo, replacing the config path as needed):
mongod --repair --config /usr/local/mongodb/mongodb.conf
Make sure there’s no lock file back in your data directory, and reload the launchctl daemon, again substituting the path to your plist file:
sudo launchctl load -w /Library/LaunchDaemons/org.mongodb.mongod.plist
And you should be back up and running. One gotcha here is that
mongod --repair does not remove the lockfile (as I had assumed) - you have to remove it yourself.