Navigation

Install MongoDB Enterprise Edition on Windows

Use this tutorial to install MongoDB Enterprise Edition 4.2 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 4.0.

Production Notes

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

System Requirements

Hardware Requirements

MongoDB Enterprise Edition requires an x86 64-bit architecture. See Supported Platforms for more information.

Software Requirements

Install on Windows 7 / Server 2008 R2 or Later

MongoDB Enterprise Edition requires Microsoft Windows Server 2008 R2 or later or Microsoft Windows 7 or later for the x86 64-bit architecture.

To find which version, service pack, and build of Windows is running on your host, as well as the processor type of that host, enter the following command in either the Command Prompt or Powershell:

systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.17134 N/A Build 17134
System Type:               x64-based PC
Show All File Name Extensions

Make certain that you set Windows Explorer/File Explorer to show file name extensions for all file types. This can prevent issues where the file type displayed to the user differs from the actual file type.

Example

If Windows Explorer/File Explorer has known file extensions hidden, what may appear to be mongod.cfg is actually mongod.cfg.txt.

Install all Windows Updates

Before installing MongoDB, update your Windows host with the latest system updates. At minimum, ensure the following Windows updates are installed on the host:

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

The Windows installer (.msi) file includes all other software dependencies and automatically upgrades any previous version of MongoDB in the same release series (3.4.1 to 3.4.2) that was installed using an .msi file. Upgrading a full release series (3.4 to 3.6) requires a new installation.

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.

Considerations

Use Command Interpreter, not Powershell

Every time this tutorial refers to the command line, you should use the Windows command interpreter (cmd.exe) with Administrative privileges. Not all commands work in Powershell.

To start cmd.exe with Administrative privileges:

  1. Open the Start menu.

    • Press the windows icon key.
    • Click on the Start windows icon icon at the left end of the taskbar.
  2. Type cmd.exe in the search box.

  3. Press Ctrl + Shift + Enter.

    This starts the Command Prompt as the Administrator user.

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.2\bin to your System PATH and then omit the full path to the MongoDB binaries.

Remember the directory where you installed MongoDB

This tutorial uses the default MongoDB Enterprise Edition location of C:\Program Files\MongoDB\Server\4.2\.

If you have installed in an alternative directory, you must adjust the paths as appropriate.

Configuration File

The installation process installs both the MongoDB binaries as well as the default configuration file <install directory>/bin/mongod.cfg.

Install MongoDB Enterprise Edition

You can install using the Windows Installer wizard or from the command line.

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

Starting in MongoDB 4.0, you can set up MongoDB as a service during the install.

1

Download MongoDB Enterprise Edition.

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

  1. The Download Center should display MongoDB Enterprise Server download information. If not, select Server, then click the MongoDB Enterprise Server tab.

  2. In the Version dropdown, select the version that corresponds to MongoDB Server 4.2. The dropdown displays the latest available point version. For older point releases, click the Archived releases link on the download center page.

    Note

    MongoDB 4.2 is currently available via the 4.1.x developer series.

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

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

1

Download MongoDB Enterprise Edition.

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

  1. The Download Center should display MongoDB Enterprise Server download information. If not, select Server, then click the MongoDB Enterprise Server tab.

  2. In the Version dropdown, select the version that corresponds to MongoDB Server 4.2. The dropdown displays the latest available point version. For older point releases, click the Archived releases link on the download center page.

    Note

    MongoDB 4.2 is currently available via the 4.1.x developer series.

  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 Windows Installer from the Windows Command Interpreter.

Important

You must open the command interpreter as an Administrator.

To install all MongoDB binaries, including MongoDB Compass, to the default installation directory, go to the directory containing the .msi installation binary and invoke:

msiexec.exe /l*v mdbinstall.log  /qb /i mongodb-win32-x86_64-enterprise-windows-64-4.1.5-signed.msi

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

msiexec.exe /l*v mdbinstall.log  /qb /i mongodb-win32-x86_64-enterprise-windows-64-4.1.5-signed.msi ^
            INSTALLLOCATION="C:\MongoDB\Server\4.2\"

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
ServerService Set up mongod.exe as a service. Use in conjunction with Server to install and set up MongoDB as a service.
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

To install just the MongoDB server and set up as a service and the mongo.exe shell, invoke:

msiexec.exe /l*v mdbinstall.log  /qb /i mongodb-win32-x86_64-enterprise-windows-64-4.1.5-signed.msi ^
            ADDLOCAL="Server,ServerService,Client"

To install only the MongoDB utilities, invoke:

msiexec.exe /l*v mdbinstall.log  /qb /i mongodb-win32-x86_64-enterprise-windows-64-4.1.5-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 /l*v mdbinstall.log  /qb /i mongodb-win32-x86_64-enterprise-windows-64-4.1.5-signed.msi ^
            SHOULD_INSTALL_COMPASS="0"

Start MongoDB Enterprise Edition from the Command Interpreter

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.2\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.2\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.2\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:

Start MongoDB Enterprise 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.

To start/restart the service, you can use the Services Manager.

You can also manage the service from the command line. To start the MongoDB service from the command line, invoke the following command:

1

Start the MongoDB service.

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

net start MongoDB
2

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.

3

Connect to the MongoDB server.

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

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

Stop MongoDB Enterprise Edition as a Windows Service

To stop/pause the MongoDB service, you can use the Services Manager.

You can also manage the service from the command line. To stop the MongoDB service from the command line, invoke the following command:

net stop MongoDB

Remove MongoDB Enterprise Edition as a Windows Service

To remove the MongoDB service, first stop the service and then run the following command:

sc.exe delete MongoDB