Search code examples
windowsmongodbbatch-filewindows-serviceswindows-server-2016

Create the MongoDB Windows Service command does nothing


When I tried to create the MongoDB Windows service following the comments given in the documentation it does nothing except return the help explanation of the windows command and exits.

This is the command (same as given in the documentation):

sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe\" ^
  --service --config=\"C:\Program Files\MongoDB\Server\3.6\mongod.cfg\""DisplayName= "MongoDB" start= "auto"

Surprisingly this has always worked on my PC running Windows 10 but not on this server. I'm running this over an AWS server running Windows Server 2016 Datacenter 64 bit OS. MongoDB v3.6.3.

How can I run this command so that I can set this up as a windows service?

create the MongoDB Windows Service command does nothing


Solution

  • My suggestion would be to either remove the caret, ^ and use a single line:

    sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.6\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
    

    Or to close the doublequotes before the caret, ^ and reopen them on the next line:

    sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe\" --service "^
     "--config=\"C:\Program Files\MongoDB\Server\3.6\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"