Installing mongodb as a service on windows

  1. Get the latest version of mongodb from here.
  2. Unpack the content of the archive wherever you need.
    1. [edit] looked at v3 at some point and could not find the binary - only msi available. in order to unpack msi use 7zip or type the following in the cmd (you may need admin rights); instaling msi will also extract it ;)
    2. msiexec /a filepath to MSI file /qb TARGETDIR=filepath to target folder
      
  3. Create a directory for the db data
  4. Prepare a mongodb config, for example:
  5. systemLog:
        destination: file
        path: "h:\\ere\\goes\\path\\to\\the\\logfile.log"
        quiet: true
        logAppend: true
    storage:
        journal:
            enabled: true
    net:
        port: 10005
        bindIp: 1270.0.0.1
    storage:
        dbPath: h:\\ere\\goes\\db\\path\\
    • starting with 2.6 cfg is in yaml, the old syntax is compatible though
    • spaces are used for indentation, tabs will not do (see)
    • paths need to be escaped
  6. Install mongodb as a service:
  7. mongod.exe --config h:\ere\goes\the\cfg\path --install
    
    • By default --install command will create a service named MongoDB; in order to adjust it have a look at the --serviceName, --serviceDisplayName and --serviceDescription params
    • By default the service will be configured to be runned under the ".\LocalSystem" not the "NT AUTHORITY\NetworkService" account as one coulde expect; If you want to specify a service user / pass use the --serviceUser and --servicePassword args

  8. And start it either through the services tab of the task manager or from the command line:
  9. net start serviceName


The service can be stopped through the services tab or from the command line:

net stop serviceName


To uninstall the service run:

mongod.exe --remove --serviceName sName
blog comments powered by Disqus