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,

kumar_88
  • 1,145
  • 2
  • 11
  • 11

1 Answers1

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.

Garrett
  • 4,007
  • 2
  • 41
  • 59
Andrew Orsich
  • 52,935
  • 16
  • 139
  • 134
  • 1
    Hi @Andrew, Thanks for your reply..For automated removal of mongo.lock file mongodb should run as deamon process? – kumar_88 Jul 28 '11 at 11:12
  • 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.... – kumar_88 Jul 28 '11 at 11:34
  • 1
    @kumar_88 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: http://www.mongodb.org/display/DOCS/Journaling – pingw33n Jul 28 '11 at 12:30
  • 1
    "you should never remove this file AUTOMATICALLY" you mean ;) – faebster Jan 12 '14 at 20:41