MongoDB:Unclean shutdown detected
When I try to start the mongod server, I get this error
************** Unclean shutdown detected. Please visit http://dochub.mongodb.org/core/repair for recovery instructions. ************* Wed May 15 08:42:54.090 [initandlisten] exception in initAndListen: 12596 old lock file, terminating Wed May 15 08:42:54.090 dbexit: Wed May 15 08:42:54.090 [initandlisten] shutdown: going to close listening sockets... Wed May 15 08:42:54.090 [initandlisten] shutdown: going to flush diaglog... Wed May 15 08:42:54.090 [initandlisten] shutdown: going to close sockets... Wed May 15 08:42:54.106 [initandlisten] shutdown: waiting for fs preallocator... Wed May 15 08:42:54.106 [initandlisten] shutdown: closing all files... Wed May 15 08:42:54.106 [initandlisten] closeAllFiles() finished Wed May 15 08:42:54.106 dbexit: really exiting now
To find the lock file open your data directory:
The reason is MongoDB uses mapped files to read and write the whole database, when the mongod process is not terminated properly, for example kill it in task manager, there are may be data corruptions. In this case, MongoDB will set this file to prevent you from working with a corrupted database.
The procedure to fix the problem is first delete the lock file and run repair command
mongod --dbpath /data/db --repair
You can just delete the lock file and start server. But there is never a reason to do that unless you don't care the data consistency.