How to run MongoDB as Windows Service

This Article is outdated!
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

mongodb 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.

Reference

  1. MongoDB as Windows Service

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
svw
Guest
svw

Mongodb is not in services list . I am using windows 8 OS . Whats is the solution for this

Borj Ano
Guest
Borj Ano

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. :)

trackback
Java MongoDB Tutorial

[…] Run MongoDB as Windows Service How to make MongoDB run as Windows Service […]

Douglas Allen
Guest
Douglas Allen

Hi. After making some blunders here I figured out that I needed to give the full path for the daemon.

C:\mongodb\bin\mongod --dbpath "c:\data\db" --logpath "c:\data\logs.txt" --install --serviceName "MongoDB"

Hope this might help someone not go through the trial and error I did.
Thanks!

trackback
How to install MongoDB on Windows

[…] In additional, you may interest this article – Install MongoDB as Windows services. […]