Hey all,
Just went through the process of installing MongoDB as a Windows Service and ran into some technical steps that were necessary to get it working. I’ll just document the steps I took to get it working to help out.
- I wanted MongoDB to run as its own user, so I created a new MongoDB user and a MongoDBUsers group. I added the MongoDB user and myself to the MongoDBUsers group.
- Open a command line and you’ll want to figure out whatever commands you normally use to start up mongod first. Once you’re set with the user and password you want, and the runtime options, you’re ready to install the service. Make sure in your options you have the dbPath and logPath specified.
- On the command line, type
C:\[fullPath]mongod.exe --install --serviceUser [userName] --servicePassword [password] [options]
It is very important that you specify the full path to the mongod executable and include “.exe” as well, no matter what directory you’re currently in. - If any of the paths in your options do not contain a space, you can skip this step. The install command used above will not include the necessary quotes you used in the options for the service command, so we’ll have to go in and manually fix that.
- Open regedit, and do a backup for safety purposes.
- Go to HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services -> [ServiceName]
- In our case, ServiceName is probably MongoDB.
- Open up the edit dialogue for ImagePath.
- Add in the necessary quotes in your options.
- Close regedit.
- Go to Administrative Tools and open up the Services list.
- Open up the MongoDB service, and go to the Log On tab.
- Hit OK, there should be a dialogue window asking if you want your user to be able to startup services, hit yes.
- You can now right click your service and startup MongoDB.
- Try to connect to it to ensure that everything is working.
Hope that helps others!