How to install MongoDB silently on Windows Server 2016

How to install MongoDB silently on Windows Server 2016

I had a hell of a time trying to figure out how to install MongoDB silently via the command line in Windows server. Although the Mongo documentation is thorough, the exact commands listed didn’t work for me out of the box.

Keep in mind that these commands work best using the standard cmd shell, and not Powershell.

After downloading MongoDB, place the msi installer on the root C: drive, and then run the following:

msiexec.exe /q /i C:\mongodb-win32-x86_64-2008plus-ssl-3.6.5-signed.msi SHOULD_INSTALL_COMPASS="0"

The key here was the SHOULD_INSTALL_COMPASS="0" snippet. Without this, the installer would get halfway through, fail, and then rollback all changes.

Before moving on to install the Windows Service, you’ll need to complete a couple preliminary steps. Create two directories using the command below:

md "\data\db" "\data\log"

Next, create a mongod.cfg file and place it in C:\Program Files\MongoDB\Server\3.6\. This file should contain the following:

systemLog:
  destination: "file"
  path: "c:\\data\\log\\mongod.log"
storage:
  dbPath: "c:\\data\\db"

If you’ve completed everything up to this point, you’re ready to create a Windows service. The command listed in the documentation didn’t work for me, either. After some finagling, the below code worked for me as well:

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"

That’s it! If you notice, the steps above are very similar to that listed in the official documentation, but these steps worked better for me. I hope this helps in some way.

One Reply to “How to install MongoDB silently on Windows Server 2016”

Leave a Reply

Your email address will not be published. Required fields are marked *