Cannot start MongoDB as a service

Have your checked you logging to see the real problem?

I suggest extracting the Mongo installation to c:\mongodb.

Create the c:\mongodb\logs and the c:\mongodb\data\db directories.

Then browse the the c:\mongodb\bin directory and run the following to remove the service (if you've installed it!):

mongod --remove

Then install the service, specifying the log and data directories:

mongod --logpath c:\mongodb\logs\mongo.log --dbpath c:\mongodb\data\db --directoryperdb --install

Then if there is a problem starting the service you should see the reason in the specified log file.

More info here.


If you did not specify absolute file paths for the data directory, or the log directory, you will get the same Windows error, but no log file.

I used the information from "Install MongoDB Service on Windows 7", pushed on Webiyo to correct the registered service arguments:

  1. Download MongoDB and extract it to the C:\ drive.
  2. Add "data" and "logs" subdirectories under the "C:\mongodb165" directory.
  3. Add a log file name "mongolog.txt" at "C:\mongodb165\logs\mongolog.txt".
  4. Change the directory to "C:\mongodb165\bin".
  5. Execute the following command:

    mongod --install --rest –master –logpath=C:\mongodb165\logs\mongolog.txt
    
  6. Open the registry editor (regedit.exe), go to HKEY_LOCAL_MACHINE → SYSTEM → CurrentControlSet → Services.

  7. Find the MongoDB key and set the "ImagePath" value to:

    C:\mongodb165\bin\mongod --service  --rest  --master  --logpath=C:\mongodb165\logs\mongolog.txt  --dbpath=C:\mongodb165\data
    
  8. Save the changes to the registry and exit the registry editor.

  9. Open ComponentServices, click on "Services (Local)", and find the MongoDB service. Start it.
  10. Check at the URL http://localhost:28017/ to verify that MongoDB returns stats.

I just encountered the same issue on my windows 7 machine. I followed the directions in MongoDBs Docs for the install, but it wouldn't let me execute "net start MongoDB" unless I was in "C:\". I didn't want to go back and reinstall MongoDB to follow the instructions included in the Webiyo link referenced above though. If you already installed MongoDB according to their docs and want to be able to execute "net start MongoDB" from where ever your project directory is:

Go to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB

Double click ImagePath under the Name column

Paste in the following ImagePath ( edit the folder directory and names to match your needs ):

C:\mongodb\bin\mongod.exe --service  --rest  --master  --logpath=C:\mongodb\log\mongolog.txt  --dbpath=C:\mongodb\data\db --config C:\mongodb\mongod.cfg

Note that if you direct copy this ImagePath value and your "data" folder is in the mongodb directory instead of C:\ add the following line to your "mongod.cfg" file: dbpath=C:\mongodb\data\db

After I did this, when I run "net stop MongoDB" I get the message "System error 109 has occurred. The pipe has been ended." You may see it as well. This message has been discussed thoroughly at jira.mongodb.org.

To save you the time of reading the whole back and forth discussion, Tad Marshalls post sums up this issue:

"... it was working fine in 2.1.0; later changes broke it again. But yes, you get this error message in the current code.

The explanation is that mongod.exe is exiting from a callback thread created by the Windows Service Control Manager when it calls us due to "net stop mongodb" and this breaks the RPC pipe it used to create the callback thread. We need to reorganize our exit logic to avoid doing this.

The error message is the only real effect of this issue; we exit on command, cleanly, and inform the Windows Service Control Manager that we are stopped, but then the "net" command displays an error message because we didn't return from the RPC call the way it expected us to."


My mongod.cfg file had the following last two lines:

#snmp:
mp:

I have no idea why there's an mp: in there. But when I manually executed the image path

C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service

at

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MongoDB

I got

c:\mongodb\bin>mongod /?C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service
Unrecognized option: mp
try 'mongod --help' for more information

So I commented it out and then the service started without any problem.