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
Tags :
Founder of Mkyong.com, love Java and open source stuffs. Follow him on Twitter, or befriend him on Facebook or Google Plus.
Here are some of my recommended Books

Related Posts

Popular Posts