Navigation

Install MongoDB Community Edition on Windows

Use this tutorial to install MongoDB Community Edition 3.6 on Windows hosts.

Note

To install a different version of MongoDB, please refer to that version’s documentation. To install the previous version, see the tutorial for version 3.4.

Prerequisites

Platform Support

MongoDB requires x86-64 architecture and supports the following:

  • Windows 7/Server 2008 R2
  • Windows 8/2012 R2 and later

See Supported Platforms for more information.

Windows Updates

Windows 2012 Server and Windows 10 need KB2999226 to provide Universal C Runtime support for Windows.

Production Notes

Before deploying MongoDB in a production environment, consider the Production Notes document.

Security

Starting with MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. From MongoDB versions 2.6 to 3.4, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages would bind to localhost by default. To learn more about this change, see Localhost Binding Compatibility Changes.

Warning

Do not expose mongod.exe to a public network without configuring authentication. MongoDB is designed to be run in trusted environments.

Install MongoDB Community Edition

You may install MongoDB Community Edition using the Windows Installer and following its wizard.

1

Download MongoDB Community Edition.

  1. Open a web browser and visit the MongoDB Download Center.
  2. The Download Center should display MongoDB Community Server tab. If not, select Server, then click the MongoDB Community Server tab.
  3. In the Version dropdown, select the version that corresponds to MongoDB Server 3.6. The download center always displays the latest available point version. For older point releases, click All version binaries in the right hand navigation box.
  4. In the OS dropdown, verify that Windows 64-bit X64 is selected.
  5. In the Package drop down, verify that MSI is selected.
  6. Click Download.
2

Open Windows Explorer.

3
4

Double-click the .msi file.

5

Follow the MongoDB Community Edition installation wizard.

If you choose the Custom installation option, you may specify an installation directory. MongoDB has no other system dependencies. You can install and run MongoDB from any directory.

You may install MongoDB MongoDB Community Edition unattended on Windows from the command line using msiexec.exe.

1

Download MongoDB Community Edition.

  1. Open a web browser and visit the MongoDB Download Center.
  2. The Download Center should display MongoDB Enterprise Server tab. If not, select Server, then click the MongoDB Enterprise Server tab.
  3. In the Version dropdown, select the version that corresponds to MongoDB Server 3.6. The download center always displays the latest available point version. For older point releases, click All version binaries in the right hand navigation box.
  4. In the OS dropdown, verify that Windows 64-bit X64 is selected.
  5. In the Package drop down, verify that MSI is selected.
  6. Click Download.
2

Run the Windows Installer from the Windows Command Interpreter.

Change to the directory containing the .msi installation binary and invoke:

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.6.13-signed.msi

To specify a different installation location for the executables, add the INSTALLLOCATION value.

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.6.13-signed.msi ^
            INSTALLLOCATION="C:\MongoDB\Server\3.6\"

By default, this method installs all MongoDB binaries. To install specific MongoDB component sets, you can specify them in the ADDLOCAL argument using a comma-separated list including one or more of the following component sets:

Component Set Binaries
Server mongod.exe
Router mongos.exe
Client mongo.exe
MonitoringTools mongostat.exe, mongotop.exe
ImportExportTools mongodump.exe, mongorestore.exe, mongoexport.exe, mongoimport.exe
MiscellaneousTools bsondump.exe, mongofiles.exe, mongoperf.exe

Example

To install only the MongoDB utilities, invoke:

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.6.13-signed.msi ^
            ADDLOCAL="MonitoringTools,ImportExportTools,MiscellaneousTools"

If you do not wish to install MongoDB Compass at this time, include the SHOULD_INSTALL_COMPASS="0" argument.

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.6.13-signed.msi ^
            SHOULD_INSTALL_COMPASS="0"

Run MongoDB Community Edition from the Command Interpreter

Open a Windows command prompt/interpreter (cmd.exe) as an Administrator.

Important

You must open the command interpreter as an Administrator.

1

Create the database directory.

Create the data directory where MongoDB stores data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB.

From the Command Interpreter, create the data directory:

cd C:\
md "\data\db"
2

Start your MongoDB database.

To start MongoDB, invoke mongod.exe.

"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --dbpath="c:\data\db"

The --dbpath option points to your database directory.

If the MongoDB database server is running correctly, the Command Interpreter displays:

[initandlisten] waiting for connections

Important

Depending on the Windows Defender Firewall settings on your Windows host, Windows may display a Security Alert dialog box about blocking “some features” of C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe from communicating on networks. To remedy this issue:

  1. Click Private Networks, such as my home or work network.
  2. Click Allow access.

To learn more about security and MongoDB, see the Security Documentation.

3

Connect to MongoDB.

To connect a mongo.exe shell to the MongoDB instance, open another Command Interpreter with Administrative privileges and run:

"C:\Program Files\MongoDB\Server\3.6\bin\mongo.exe"

For more information on connecting a mongo.exe shell, such as to connect to a MongoDB instance running on a different host and/or port, see The mongo Shell. For information on CRUD (Create,Read,Update,Delete) operations, see MongoDB CRUD Operations.

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.

Run MongoDB Community Edition as a Windows Service

Start MongoDB Community Edition as a Windows Service

You can set up the MongoDB server as a Windows Service that starts automatically at boot time.

1

Create the database and log directories.

If you have not created the data and log directories for your MongoDB server, you must create them before running MongoDB Community Edition as a Windows service.

From the Command Interpreter, create the following directories:

cd C:\
md "\data\db" "\data\log"
2

Create a MongoDB configuration file.

Create a MongoDB configuration file:

C:\Program Files\MongoDB\Server\3.6\mongod.cfg

Note

MongoDB configuration files use the YAML file format. Per the YAML 1.2 specification, all indents must use spaces to maintain portability. To ensure no parsing errors, enclose all values in double quotation marks (") and escape any backslash characters (\).

Set the storage.dbPath and systemLog.path. Include additional configuration options as needed:

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

Create the MongoDB service.

Invoke the following command in the Command Interpreter to create the service:

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

Note

sc.exe requires a space between “= ” and the configuration values (i.e. binPath= `` ) as well as using `` "\" and \"" to escape a double-quoted string.

If successfully created, the following message is written to the log:

 [SC] CreateService SUCCESS
4

Start the MongoDB service.

Close all other command prompts, then invoke the following command:

net start MongoDB
5

Verify that MongoDB has started successfully.

Check your MongoDB log file for the following line:

[initandlisten] waiting for connections on port 27017

You may see non-critical warnings in the process output. As long as you see this message in the MongoDB log, you can safely ignore these warnings during your initial evaluation of MongoDB.

6

Connect to the MongoDB server.

To connect to MongoDB through the mongo.exe shell, open another Command Interpreter.

"C:\Program Files\MongoDB\Server\3.6\bin\mongo.exe"

Stop MongoDB Community Edition as a Windows Service

To stop/pause the MongoDB service, use the Services console:

  1. From the Services console, locate the MongoDB service.
  2. Right-click on the MongoDB service and click Stop (or Pause).

You can also stop the MongoDB service from the Windows command prompt/interpreter (cmd.exe). Open a Windows command prompt/interpreter (cmd.exe) as an Administrator, and run the following command:

net stop MongoDB

Remove MongoDB Community Edition as a Windows Service

To remove the MongoDB service, first use the Services console to stop the service. Then open a Windows command prompt/interpreter (cmd.exe) as an Administrator, and run the following command:

sc.exe delete MongoDB

Additional Considerations

Point Releases and .msi

If you installed MongoDB with the Windows installer (.msi), the .msi automatically upgrades within the same release series (e.g. 3.6.0 to 3.6.1).

Upgrading a full release series (e.g. 3.4 to 3.6) requires a new installation.

Add MongoDB binaries to the System PATH

All command-line examples in this tutorial are provided as absolute paths to the MongoDB binaries. You can add C:\Program Files\MongoDB\Server\3.6\bin to your System PATH and then omit the full path to the MongoDB binaries.