First of all, mongod.lock是mongo服务端启动后在硬盘中创建的一个锁文件,如果你正常退出mongod服务,该文件即使还存在,也不会影响下一次启动mongodservice. At the same time, this file will also record some status of mongod during operation, so that exception information prompts can be obtained when the service is restarted normally.
Note: Generally, files can only be exited mongod服务时,才需要删除mongod.lock abnormally. Exit normally, no need to delete.
Now the data is lost, it should be an abnormal exit, that is, the database crashes. If there is no 开启journal, then there is no way to ensure the integrity of the data.
So it usually happens in a production environment开启journal.
If the data is not backed up, you can only try to use mongod's built-in repair, run mongod加上--repair option:
mongod --dbpath /path/to/corrupt/data --repair
Do you want to delete the mongod.lock file?
When mongod is shut down normally, the mongod.lock file will be cleared. The next time you start it, you will know that it was completely shut down last time. On the contrary, if the lock file is not cleared, mongod does not shut down gracefully.
If mongod detects that there is no normal shutdown, it will not let you start again. When starting, it will print information about the last abnormal shutdown, and you will need to copy a copy of the data. However, some people have realized that this check can be bypassed by deleting the lock file. So there is a reason to delete this file. Deleting the lock file at startup means you don't know or care if your data has been corrupted. If you cannot start mongod, please repair your data instead of deleting the lock file.
Solution
First of all,
mongod.lock
是mongo
服务端启动后在硬盘中创建的一个锁文件,如果你正常退出mongod
服务,该文件即使还存在,也不会影响下一次启动mongod
service. At the same time, this file will also record some status of mongod during operation, so that exception information prompts can be obtained when the service is restarted normally.Note: Generally, files can only be exited
mongod
服务时,才需要删除mongod.lock
abnormally. Exit normally, no need to delete.Now the data is lost, it should be an abnormal exit, that is, the database crashes. If there is no
开启journal
, then there is no way to ensure the integrity of the data.So it usually happens in a production environment
开启journal
.If the data is not backed up, you can only try to use mongod's built-in repair, run
mongod
加上--repair
option:Do you want to delete the
mongod.lock
file?When mongod is shut down normally, the mongod.lock file will be cleared. The next time you start it, you will know that it was completely shut down last time. On the contrary, if the lock file is not cleared, mongod does not shut down gracefully.
If mongod detects that there is no normal shutdown, it will not let you start again. When starting, it will print information about the last abnormal shutdown, and you will need to copy a copy of the data. However, some people have realized that this check can be bypassed by deleting the lock file. So there is a reason to delete this file. Deleting the lock file at startup means you don't know or care if your data has been corrupted. If you cannot start mongod, please repair your data instead of deleting the lock file.