Possible Errors and recovery
Bad Shutdown: (Unable to lock file: /data/db/mongod.lock)
Occasionally, mongo will be improperly shutdown, like closing the terminal before exiting
$ ctrl + c
And you’ll see the following error
2017-01-01T12:00:00.000-0400 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to lock file: /data/db/mongod.lock Resource temporarily unavailable. Is a mongod instance already running?, terminating
To fix, first try to recover graceful…
mongod --dbpath /data/db --repair
If that doesn’t work remove the old lock file.
rm /data/db/mongod.lock
For more information checkout https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/ Address in Use: (addr already in use)
If you get an the following error:
2017-01-01T12:00:00.000-0400 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017 2017-01-01T12:00:00.000-0400 E NETWORK [initandlisten] addr already in use
Then a mongod is still running in the background, find and kill the process. There are a few find and kill the process PID
a. Find and Kill mongod process by name
pkill mongod
b. Find mongod PID (Process ID) by name pgrep mongod
8549 << This is the PID (Process ID)
c. Find mongod PID (Process ID) using PS (process status) and grep ps -ef | grep mongod
8549 << This is the PID (Process ID)
d. Terminate (kill) process using the PID from kill kill 8549
Also can do this…
Activity Monitor on MacOS will work too On Windows, you can probably do this with Task Manager Fix WARNINGS Get rid of: ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 Mac users, in the terminal,
ulimit -n 2048 mongod ;-)
Get rid of: ** WARNING: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted.
Short Version: https://stackoverflow.com/a/42926515/3109731 Official Documentation https://docs.mongodb.com/manual/tutorial/enable-authentication/