What is the use of the mongo.lock file?
Asked Answered
W

1

19

I am using mongodb-v1.8.1. Unfortunately my server gets hanged and i restarted my server.Once it comes back i could-not start the MongoDB. I removed the mongo.lock file and ran repair database query.Now mongo working fine. I am baffled with the mongo.lock file.What is the use of the mongo.lock file?.Removing the mongo.lock file will affect my existing data? Please let me know your suggestion..

Thanks,

Whirligig answered 28/7, 2011 at 10:52 Comment(2)
what's the repair database query?Pritchard
mongod --dbpath /data/db --repair from: docs.mongodb.com/manual/tutorial/…Hyderabad
Y
27

Mongodb always creates the mongodb.lock file when the server starts and drops it before mongodb is stopped.

Removing mongodb.lock does not affect any data it just means that mongodb was not stopped correctly. So, you are correct in removing this file and running with the -repair option should fix database.

Yorktown answered 28/7, 2011 at 11:9 Comment(4)
Hi @Andrew, Thanks for your reply..For automated removal of mongo.lock file mongodb should run as deamon process?Whirligig
Hi @Andrew, I am not running mongo as daemon process.Do i have to run as daemon?.If mongo run as daemon it would remove the file whenever the server restarts?..Please provide information on this....Whirligig
@Whirligig you should never remove this file manually. If you happen to have to you possibly has already lost some data. If you suffer from this consider enabling journaling: mongodb.org/display/DOCS/JournalingBamby
"you should never remove this file AUTOMATICALLY" you mean ;)Brod

© 2022 - 2024 — McMap. All rights reserved.