Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
svw
9 years ago

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

Borj Ano
7 years ago
Reply to  svw

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

Douglas Allen
11 years ago

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!