Install using msiexec.exe
The following tutorial uses msiexec.exe
from the command line toinstall MongoDB Community Edition 4.2 on Windows. To install using the MongoDB installation wizard, see Install MongoDB Community Edition on Windows 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 need KB2999226 to provide Universal C Runtime support forWindows.
Production Notes
Before deploying MongoDB in a production environment, consider theProduction Notes document.
Install MongoDB Community Edition
You can install MongoDB MongoDB Community Edition unattended on Windows from theWindows command prompt/interpreter (cmd.exe
) using msiexec.exe
.
Download MongoDB Community Edition.
Download the installer (.msi
) from the MongoDB Download Center:
- The Download Center should display MongoDB Community Server download information. If not,select Server, then click the MongoDB Community 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 Windows Installer from the Windows Command Interpreter.
Important
You must open the command interpreter as anAdministrator.
- Windows 8 or greater
- Windows 7
For Windows 8 or greater, you can use the .msi
toinstall all MongoDB binaries, including MongoDB Compass.
From the Command Interpreter, go to the directory containing the.msi
installation binary and run:
- msiexec.exe /l*v mdbinstall.log /qb /i mongodb-win32-x86_64-2012plus-4.2.1-signed.msi
The operation installs the binaries to the default directoryC:\Program Files\MongoDB\Server\4.2\bin
.
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-2012plus-4.2.1-signed.msi ^
- INSTALLLOCATION="C:\MongoDB\Server\4.2\"
To suppress the installation of MongoDBCompass, you must explicitly include theSHOULD_INSTALL_COMPASS="0"
argument.
- msiexec.exe /l*v mdbinstall.log /qb /i mongodb-win32-x86_64-2012plus-4.2.1-signed.msi ^
- SHOULD_INSTALL_COMPASS="0"
To install specific MongoDB component sets, you can specify them inthe ADDLOCAL
argument using a comma-separated list including oneor more of the following component sets:
Component Set Name | Binaries Included in the Component Set |
---|---|
ServerNoService | mongod.exe |
ServerService | Set up mongod.exe as a Windows 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 |
For example, to install just the MongoDB server(mongod.exe
) and the mongo.exe
shell as well asset up the MongoDB server as a Windows service, run:
- msiexec.exe /l*v mdbinstall.log /qb /i mongodb-win32-x86_64-2012plus-4.2.1-signed.msi ^
- ADDLOCAL="ServerService,Client" ^
- SHOULD_INSTALL_COMPASS="0"
To include Compass in the installs, remove SHOULD_INSTALL_COMPASS="0"
.
For Windows 7, you can use the .msi
to install allMongoDB binaries except MongoDB Compass since the.msi
installer requires PowerShell version 3.0 orgreater to install Compass. You can manually installCompass from the Download Center.
From the Command Interpreter, go to the directorycontaining the .msi
and run the following command:
Note
The command includes the SHOULD_INSTALL_COMPASS="0"
argument to suppress the installation of MongoDBCompass.
- msiexec.exe /l*v mdbinstall.log /qb /i mongodb-win32-x86_64-2012plus-4.2.1-signed.msi ^
- SHOULD_INSTALL_COMPASS="0"
The operation installs the binaries to the default directoryC:\Program Files\MongoDB\Server\4.2\bin
.
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-2012plus-4.2.1-signed.msi ^
- INSTALLLOCATION="C:\MongoDB\Server\4.2\" ^
- SHOULD_INSTALL_COMPASS="0"
To install specific MongoDB component sets, you can specify them inthe ADDLOCAL
argument using a comma-separated list including oneor more of the following component sets:
Component Set | Binaries |
---|---|
ServerNoService | mongod.exe |
ServerService | Set up mongod.exe as a Windows 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 |
For example, to install just the MongoDB server(mongod.exe
) and the mongo.exe
shell as well asset up the MongoDB server as a Windows service, run:
- msiexec.exe /l*v mdbinstall.log /qb /i mongodb-win32-x86_64-2012plus-4.2.1-signed.msi ^
- ADDLOCAL="ServerService,Client" ^
- SHOULD_INSTALL_COMPASS="0"
Start 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 anAdministrator.
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"
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 yourdatabase directory.
If the MongoDB database server is running correctly, theCommand Interpreter displays:
- [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.exe
from 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:
- "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 differenthost and/or port, see The mongo Shell. For information on CRUD(Create,Read,Update,Delete) operations, see:
Run MongoDB Community Edition as a Windows Service
Start MongoDB Community 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.
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:
- net start MongoDB
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 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.exe
shell, open another Command Interpreter.
- "C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
Stop MongoDB Community Edition as a Windows Service
To stop/pause the MongoDB service, you can 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:
- net stop MongoDB
Remove MongoDB Community 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:
- 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
), 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 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.