Search my blog
Custom Search

Tuesday, November 5, 2013

MongoDB fails to start as Windows Service on Windows 7

It took me half day to figure out the issue. 

The original command to run the mongod as service is as below.
mongod --logpath ".\logs.txt" --dbpath ".\db" --noauth --install --rest --journal

The scripts run without any problem if I remove "--install". This won't run as windows service.

However, as soon as I run with "--install" and tries to start from service control. The "mongdb" service keep switching between "started" and "starting" status.

The windows event view reports numerous errors as "the mongodb service is terminated and will be restarted".


Fix:
Do not use "relative path' in the parameters. 
For eample in my case:
mongod --logpath "C:\Mongo\logs.txt" --dbpath "C:\Mongo\db" --noauth --install --rest --journal

Reason:
When running as a service, the starting directory is not relative to the "mongod.exe" and thus the DB path cannot be found.