MongoDB: Setting up Windows Service

There is a known issue installing MongoDB 2.6.0 as a Windows service using the --install command - see SERVER-13515. A fix has been committed for the MongoDB 2.6.1 release.

As a workaround, I've provided instructions on how to install the service manually on that SERVER issue.

The short version is:

  • open an Administrator cmd prompt
  • make directories for your database and log files
  • create a configuration file
  • create the service definition, similar to:

    sc create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
    
  • start the MongoDB service

    net start MongoDB
    

For full instructions please refer to SERVER-13515.

I'm also very confused as to the difference between mongo.conf and mongod.cfg

The MongoDB server doesn't care about the name/extension of the file you specify with --config (as long as the file can be read). Your confusion on the format is because the mongo.conf example uses the new YAML config file format supported by MongoDB 2.6+, while mongod.cfg uses the older format supported by 2.6 as well as earlier versions.

I used the older mongod.cfg format in my workaround example, as technically someone could adapt these instructions to manually create a service definition for MongoDB 2.4 as well.


I was having a similar problem with Mongo 2.6.3. I was trying to set the log path to C:\Users\Public\Public Databases\Mongo\log\mongo.log and the service installer kept responding with Failed to open ""C:\Program Files\MongoDB 2.6 Standard\bin\Users\Public\Public Databases\Mongo\log\mongo.log"".

It started working for me when I stopped quoting the log path in the config file. (i.e. I changed logpath="C:\Users\Public\Public Databases\Mongo\log\mongo.log" to logpath=C:\Users\Public\Public Databases\Mongo\log\mongo.log).


I got the same problem not only when installing as a Windows service but also when running "mongodb.exe" file. I tried to remove double quote (") characters but the error was still there:

2014-08-16T14:14:49.166Z SEVERE: Failed global initialization: FileNotOpen Failed to open "D:\MongoDB\log\mongo.log"

Please note that I was using config file in new YAML format. I had no problem when using the old format. I tried several ways on the new YAML configuration file and finally I found that it doesn't accept the absolute path. Just change to relative path and it works like a charm!

My folder structure is:
MongoDB\
   bin\
   data\
   log\

Here is my YAML configuration file that works on the build MongoDB 2.6.4 - Windows 64 bit version, installed on my Windows 7 - Professional x64:

systemLog:
   timeStampFormat: iso8601-utc
   destination: file
   path: ..\log\mongo.log
   quiet: false
   logAppend: true
net:
   bindIp: 127.0.0.1
   port: 27017
storage:
   dbPath: ..\data
   directoryPerDB: true
   journal:
      enabled: true

Tags:

Mongodb