Navigation

Install MongoDB Community Edition on Windows

The following tutorial uses the MongoDB installer .msi to install MongoDB Community Edition 4.0 on Windows. To install using the msiexec.exe from the command line (cmd.exe), see Install using msiexec.exe instead.

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.6.

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.

Install MongoDB Community Edition

Note

You can also spin up MongoDB on Azure using Atlas, our fully-managed database-as-a-service. Atlas enables you to configure anything from a free sandbox environment to a globally sharded production cluster. Set up a free cluster now.

You can install using the MongoDB Installer wizard. The installation process installs both the MongoDB binaries as well as the default configuration file <install directory>\bin\mongod.cfg.

1

Download MongoDB Community Edition.

Download the installer (.msi) from the MongoDB Download Center:

  1. The Download Center should display MongoDB Community Server download information. If not, select Server, then click the MongoDB Community Server tab.
  2. In the Version dropdown, select the version that corresponds to MongoDB Server 4.0. The dropdown displays the latest available point version. For older point releases, click the All version binaries link on the download center page.
  3. In the OS dropdown, verify that Windows 64-bit X64 is selected.
  4. In the Package drop down, verify that MSI is selected.
  5. Click Download.
2

Run the MongoDB installer

From the Windows Explorer/File Explorer:

  1. Navigate to the directory in which you downloaded the MongoDB installer (.msi file). By default, this is %HOMEPATH%\Downloads.
  2. Double-click the .msi file.
3

Follow the MongoDB Community Edition installation wizard.

The wizard steps you through the installation of MongoDB and MongoDB Compass.

  1. Choose Setup Type

    You can choose either the Complete (recommended for most users) or Custom setup type. If you choose the Custom installation option, you may specify which executables are installed and where.

  2. Service Configuration

    Starting in MongoDB 4.0, you can set up MongoDB as a service during the install or just install. Click on the appropriate tab for instructions.

    The following installs and configures MongoDB as a service. To install only, click on the appropriate tab.

    Starting in MongoDB 4.0, you can configure and start MongoDB as a service during the install, and the MongoDB service is started upon successful installation.

    Image of the MongoDB Installer wizard - Service Configuration.
    • Select Install MongoD as a Service MongoDB as a service.
    • Select to Run the service as one of the following users:
      • Network Service user (Default); i.e. a Windows user account that is built-in to Windows
      • Local or domain user:
        • For an existing local user account, specify a period (i.e. .) for the Account Domain and specify the Account Name and the Account Password for the user.
        • For an existing domain user, specify the Account Domain, the Account Name and the Account Password for that user.
    • Service Name. Specify the service name. Default name is MongoDB. If you already have a service with the specified name, you must choose another name.
    • Data Directory. Specify the data directory, which corresponds to the --dbpath. If the directory does not exist, the installer will create the directory and sets the directory access to the service user.
    • Log Directory. Specify the Log directory, which corresponds to the --logpath. If the directory does not exist, the installer will create the directory and sets the directory access to the service user.

    The following installs MongoDB only and does not configure MongoDB as a service. To install and configure MongoDB as a service, click on the appropriate tab.

    If you choose not to configure MongoDB as a service, uncheck the Install MongoD as a Service.

    Image of the MongoDB Installer wizard. Not as a service.
  3. Install MongoDB Compass

    To install MongoDB Compass, select Install MongoDB Compass (Default).

  4. When ready, click Install.

    If you installed and configured MongoDB as a service, the MongoDB service is started upon successful installation. MongoDB is configured using the configuration file <install directory>\bin\mongod.cfg.

Run MongoDB Community Edition as a Windows Service

Starting in version 4.0, you can install and configure MongoDB as a Windows Service during the install, and the MongoDB service is started upon successful installation. MongoDB is configured using the configuration file <install directory>\bin\mongod.cfg.

Start MongoDB Community Edition as a Windows Service

To start/restart 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 Start.

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

"C:\Program Files\MongoDB\Server\4.0\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:

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).

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

Run MongoDB Community Edition from the Command Interpreter

You can run MongoDB Community Edition from the Windows command prompt/interpreter (cmd.exe) instead of as a service.

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

Important

You must open the command interpreter as an Administrator.

1

Create 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 directories:

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

Start your MongoDB database.

To start MongoDB, run mongod.exe.

"C:\Program Files\MongoDB\Server\4.0\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\4.0\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\4.0\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:

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. 4.0.1 to 4.0.2).

Upgrading a full release series (e.g. 4.0 to 4.2) 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\4.0\bin to your System PATH and then omit the full path to the MongoDB binaries.