How to run MongoDB as Windows Service
This Article is outdated!
Please refer to this latest guide to install MongoDB as Windows Service.
Please refer to this latest guide to install MongoDB as Windows Service.
A guide to show you how to installed MongoDB on Windows.
1. mongod –help
Get to know all the Windows service related commands by typing “mongod --help
“.
C:\MongoDB\bin>mongod --help
Windows Service Control Manager options:
--install install mongodb service
--remove remove mongodb service
--reinstall reinstall mongodb service (equivilant of mongod
--remove followed by mongod --install)
--serviceName arg windows service name
--serviceDisplayName arg windows service display name
--serviceDescription arg windows service description
--serviceUser arg user name service executes as
--servicePassword arg password used to authenticate serviceUser
Two --install
and --remove
arguments are what you need.
2. Install as Windows Service
To install as a Windows service, issue “mongod --install
“, for example :
#> mongod --dbpath "c:\mymongodb" --logpath "c:\mymongodb\logs.txt" --install --serviceName "MongoDB"
all output going to: c:\mymongodb\logs.txt
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.
It means, install a MongoDB, which point to “c:\mymongodb
” data directory, log output to “c:\mymongodb\logs.txt
“, and a Windows service named “MongoDB“.
Figure : MongoDB is installed as Windows Service
3. Uninstall It
To uninstall above installed MongoDB service, issue “mongod --remove
“, along with the installed service name.
#> mongod --remove --serviceName "MongoDB"
Deleting service MongoDB.
Service deleted successfully.
Fri Apr 29 18:39:06 dbexit:
Fri Apr 29 18:39:06 shutdown: going to close listening sockets...
Fri Apr 29 18:39:06 shutdown: going to flush diaglog...
Fri Apr 29 18:39:06 shutdown: going to close sockets...
Fri Apr 29 18:39:06 shutdown: waiting for fs preallocator...
Fri Apr 29 18:39:06 shutdown: closing all files...
Fri Apr 29 18:39:06 closeAllFiles() finished
Fri Apr 29 18:39:06 dbexit: really exiting now
Done.
Mongodb is not in services list . I am using windows 8 OS . Whats is the solution for this
Make sure you install it as an Administrator. In case you are installing through Power shell editor, make sure you run it as an Administrator as well. 🙂
Hi. After making some blunders here I figured out that I needed to give the full path for the daemon.
Hope this might help someone not go through the trial and error I did.
Thanks!
Thanks for your input.
It’s better to defined the MongoDB configuration values in a config file, and start it like this :
Refer to the latest guide to install MongoDB as Windows service.