Install MongoDB Enterprise Edition on Windows

The following tutorial uses the MongoDB installation wizard to installMongoDB Enterprise Edition 4.2 on Windows. To install using themsiexec.exe from the command line (cmd.exe), seeInstall using msiexec.exe instead.

Note

To install a different version of MongoDB, please refer to thatversion’s documentation. To install the previous version, seethe tutorial for version 4.0.

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 needKB2999226to provide Universal C Runtime support for Windows.

Production Notes

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

Install MongoDB Enterprise Edition

You can install MongoDB Enterprise Edition using the Windows Installation wizard.The installation process installs both the MongoDB binaries as well asthe default configuration file <installdirectory>\bin\mongod.cfg.

Download MongoDB Enterprise Edition.

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

  • The Download Center should display MongoDB Enterprise Server download information. If not,select Server, then click the MongoDB Enterprise Server tab.
  • In the Version dropdown, select the version thatcorresponds to the latest MongoDB Server 4.2.
  • In the OS dropdown, Windows 64-bit X64should be selected.
  • In the Package drop down, MSI should beselected.
  • Click Download.

Run the MongoDB installer.

For example, from the Windows Explorer/File Explorer:

  • Go to the directory where you downloaded the MongoDB installer (.msi file).By default, this is your Downloads directory.
  • Double-click the .msi file.

Follow the MongoDB Enterprise Edition installation wizard.

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

    • Choose Setup Type
    • You can choose either the Complete (recommended formost users) or Custom setup type. TheComplete setup option installs MongoDB and theMongoDB tools to the default location. The Customsetup option allows you to specify which executables areinstalled and where.
    • Service Configuration
    • Starting in MongoDB 4.0, you can set up MongoDB as a Windows serviceduring the install or just install the binaries.
  1. - MongoDB Service
  2. - MongoDB

The following installs and configures MongoDB as a Windowsservice.

Starting in MongoDB 4.0, you can configureand start MongoDB as a Windows service during the install, andthe MongoDB service is started upon successfulinstallation.

Image of the MongoDB Installer wizard - Service Configuration.

  1. -

Select Install MongoD as a Service MongoDB as a service.

  1. -

Select either:

  1. -

Run the service as Network Service user (Default)

This is a Windows user account that is built-into Windows

or

  1. -

Run the service as a local or domain user

  1. - For an existing local user account, specify aperiod (i.e. <code>.</code>) for the AccountDomain and specify the Account Name andthe Account Password for the user.
  2. - For an existing domain user, specify theAccount Domain, theAccount Name and theAccount Password for that user.
  3. -

Service Name. Specify the servicename. Default name is MongoDB. If you alreadyhave a service with the specified name, you mustchoose another name.

  1. -

Data Directory. Specify the datadirectory, which corresponds to the—dbpath. If thedirectory does not exist, the installer willcreate the directory and sets the directory accessto the service user.

  1. -

Log Directory. Specify the Logdirectory, which corresponds to the—logpath. If thedirectory does not exist, the installer willcreate the directory and sets the directory accessto the service user.

The following installs MongoDB only and does notconfigure MongoDB as a Windows service.

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

Image of the MongoDB Installer wizard. Not as a service.

    • Install MongoDB Compass
    • For Windows 8 or greater, you can have the wizard installMongoDB Compass.To install Compass, select Install MongoDB Compass (Default).

Note

The install script requires PowerShell version 3.0 orgreater. If you have Windows 7, unclick theInstall MongoDB Compass. You canmanually download Compass from the DownloadCenter.

  • When ready, click Install.

If You Installed MongoDB as a Windows Service

The MongoDB service is started upon successful installation [1].

To begin using MongoDB, connect a mongo.exe shellto the running MongoDB instance. Either:

  • From Windows Explorer/File Explorer, go to C:\ProgramFiles\MongoDB\Server\4.2\bin\ directory and click onmongo.exe.

  • Or, open a Command Interpreter with Administrativeprivileges and run:

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

For information on CRUD (Create,Read,Update,Delete)operations, see:

[1]The MongoDB instance is configured using the configuration file<install directory>\bin\mongod.cfg.

If You Did Not Install MongoDB as a Windows Service

If you only installed the executables and did not install MongoDB as aWindows service, you must manually start the MongoDB instance.

See Start MongoDB Enterprise Edition from the Command Interpreter for instructions to start aMongoDB instance.

Start MongoDB Enterprise Edition from the Command Interpreter

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:

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

Start your MongoDB database.

To start MongoDB, run mongod.exe.

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

The —dbpath option points to yourdatabase directory.

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

  1. [initandlisten] waiting for connections

Important

Depending on theWindows Defender Firewallsettings on your Windows host, Windows may display aSecurity Alert dialog box about blocking“some features” of C:\Program Files\MongoDB\Server\4.2\bin\mongod.exefrom communicating on networks. To remedy this issue:

  • Click Private Networks, such as my home or worknetwork.
  • Click Allow access.To learn more about security and MongoDB, see theSecurity Documentation.

Connect to MongoDB.

To connect amongo.exe shell to the MongoDB instance, open anotherCommand Interpreter with Administrative privileges and run:

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

For more information on connecting a mongo.exeshell, such as to connect to a MongoDB instance running on a differenthost 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 aWindows Service during the install, and the MongoDB serviceis started upon successful installation.

To start/restart the MongoDB service, use the Services console:

  • From the Services console, locate the MongoDB service.
  • Right-click on the MongoDB service and click Start.To begin using MongoDB, connect a mongo.exe shellto the running MongoDB instance. To connect, open a CommandInterpreter with Administrative privileges and run:
  1. "C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"

For more information on connecting a mongo.exeshell, such as to connect to a MongoDB instance running on a differenthost and/or port, see The mongo Shell. For information on CRUD(Create,Read,Update,Delete) operations, see:

You can also manually manage the service from the command line. Tostart the MongoDB service from the command line, open a Windowscommand prompt/interpreter (cmd.exe) as an Administrator, andrun the following command:

Start the MongoDB service.

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

  1. net start MongoDB

Verify that MongoDB has started successfully.

Check your MongoDB log file for the following line:

  1. [initandlisten] waiting for connections on port 27017

You may see non-critical warnings in the processoutput. As long as you see this message in the MongoDB log, you cansafely ignore these warnings during your initial evaluation ofMongoDB.

Connect to the MongoDB server.

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

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

Stop MongoDB Enterprise Edition as a Windows Service

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

  • From the Services console, locate the MongoDB service.
  • Right-click on the MongoDB service and click Stop (or Pause).You can also manage the service from the command line. To stop theMongoDB service from the command line, open a Windows commandprompt/interpreter (cmd.exe) as an Administrator, andrun the following command:
  1. net stop MongoDB

Remove MongoDB Enterprise Edition as a Windows Service

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

  1. sc.exe delete MongoDB

Additional Considerations

Security

Starting with MongoDB 3.6, MongoDB binaries, mongod.exe and mongos.exe, bind tolocalhost by default.

When bound only to the localhost, these binaries can only acceptconnections from clients that are running on the same machine. Remoteclients cannot connect to the binaries bound only to localhost. Formore information, including how to override and bind to other ipaddresses, see Localhost Binding Compatibility Changes.

Point Releases and .msi

If you installed MongoDB with the Windows installer (.msi), that.msi automatically upgrades within its 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 newinstallation.

Add MongoDB binaries to the System PATH

All command-line examples in this tutorial are provided as absolutepaths to the MongoDB binaries. You can add C:\ProgramFiles\MongoDB\Server\4.2\bin to your System PATH and thenomit the full path to the MongoDB binaries.