I am not sure why, and the service was working fine just yesterday, all of a sudden I can not get MongoDB to start up.
[root@purr ~]# service mongod start
St
In my case, it was also showing some lock problems whenever my local system shuts down without stopping the MongoDB server.
But it just worked only by using sudo command:-
$ sudo mongod --port 27017
After running the repair I was able to start the mongod proccessor but as root, which meant that service mongod start
would not work. To repair this issue, I needed to make sure that all the files inside the database folder were owned and grouped to mongod. I did this by the following:
/var/lib/mongo
I went to cd /var/lib
ls -l mongo
chown -R mongod:mongod mongo
. This changed the owner and group of every file in the folder to mongod. (If using the mongodb package, chown -R mongodb:mongodb mongodb
)I hope this helps someone else in the future.
I solved this by deleting d:\test\mongodb\data\mongod.lock file. When you will reconnect mongo db than this file will auto generate in same folder. it works for me.
I tried deleting the lock file, but the real reason that this happened to me was because I was using ~/data/db as the data directory. Mongo needs an absolute path to the database. Once I changed it to /home//data/db, I was in business.
Delete the .lock file from the C:\mongodb\data\ path and then restart the mongodb service.
I can't upvote/comment yet, but +1 for manually removing the lock file haha.
My C9 workspace crashed on me and triggered an unexpected shutdown. The API advises: https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/
.. but removing data/mongo.lock worked for me :).
Also, just in case you're getting a connection refusal (which happened to me), running the repair command before removing the lock file could solve your problem (it did mine).
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/