How to Install MongoDB on Windows 10/Windows Server 2016

In this tutorial I am going to explain how to download and Install MongoDB on Windows 10/ Windows Server 2016.
Following are the steps you need to follow in order to install MongoDB on Microsoft Windows 10 / Windows Server 2016.

Download MongoDB for Windows

The download  for the Microsoft Windows for the MongoDB comes as a .msi installer.  The .msi installer also includes all other software dependencies that need to run mongodb on windows.

Go to mongodb download page, select the community server and download the .msi installer to your computer.

Download MongoDB for Windows

Run MongoDB Installer

Once the download is finished, run .msi file to install MongoDB in Windows.

If you go with the default installation options, mongodb will be installed to the "C:\Program Files\MongoDB" folder.

Create Data and Logs Folders

We need to create the Data folder for the NoSQL database server as well as Logs folder. MongoDB installer does not create these data directories, so we need to create them manually.

mkdir c:\mongo\data
mkdir c:\mongo\logs

Create mongod.cfg configuration file

We need to create the Configuration file for the MongoDB Server. Create a new file called 'mongod.cfg'  at 'c:\mongo\'  (Look for the file extension, by default windows hide the .txt file extension) and add following configurations to the configuration file.

    destination: file
    path: c:\mongo\logs\mongod.log
    dbPath: c:\mongo\data
      serviceName: "MongoDB"
      displayName: "Mongo DB"
      description: "mongod service"

Start MongoDB from the Command Line

At this point we are ready to start MongoDB server on windows using the windows CMD. To start MongoDB we need to run the mongod.exe which is in the bin directory of the mongodb installation folder.

The --config option need to specify the path to the mongod.cfg file.

"c:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --config "c:\mongo\mongod.cfg"
start mongodb on windows

In a separate window run the mongo.exe file to open mongo shell:

"c:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"

Setting up MongoDB as a windows service

It is easy to manage MongoDB database server if you configure mongodb as Windows service.

To create windows service, we use the same command we used to start the MongoDB server with --install flag.

"c:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --config "c:\mongo\mongod.cfg" --install

Now if you go to the windows services manager, you will see the  "Mongo DB" service. From the services manager, you can set "Startup Type" to "Automatic" to start MongoDB service at system reboot.

Start/Stop MongoDB Server on Windows 10/Server 2016

We can now start and stop mongodb service from the command line with the net command.

To Start MongoDB from the Command Line, Type:

net start MongoDB

To stop MongoDB Service, Type:

net stop MongoDB

Add MongoDB binaries to the Windows PATH variable

Add MongoDB binary location to your windows system path so you can start mongodb shell from the windows cmd without having to specify the full pathname.

The binaries are located inside the bin directory under the installation directory.

Go to Control Panel > System and Security > System > Advanced System Settings and Click Environment Variables.

Under the system variables, edit the PATH variable and append the full path to the bin directory.

Add MongoDB binaries to the Windows PATH variable

With PATH variable is set, you can simply type mongo in the windows command line to access mongo shell.