- Install MongoDB >
- Install MongoDB Community Edition >
- Install MongoDB Community Edition on Windows
Install MongoDB Community Edition on Windows¶
On this page
- System Requirements
- Considerations
- Install MongoDB Community Edition
- Start MongoDB Community Edition from the Command Interpreter
- Start MongoDB Community Edition as a Windows Service
- Stop MongoDB Community Edition as a Windows Service
- Remove MongoDB Community Edition as a Windows Service
- Additional Resources
Use this tutorial to install MongoDB Community Edition 4.0 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.6.
Production Notes
Before deploying MongoDB in a production environment, consider the Production Notes document.
System Requirements¶
Hardware Requirements¶
MongoDB Community 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 Community 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:
- 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.cfgis actuallymongod.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:
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:
-
- Press the windows icon key.
- Click on the Start windows icon icon at the left end of the taskbar.
Type
cmd.exein the search box.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.0\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 Community Edition location of
C:\Program Files\MongoDB\Server\4.0\.
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 Community Edition¶
You can install using the Windows Installer wizard or from the command line.
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.
- Interactive Installation (Windows Installer Wizard)
- Unattended Installation
You may install MongoDB Community 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.
Download MongoDB Community Edition.¶
- Open a web browser and visit the MongoDB Download Center.
- The Download Center should display the Current Stable Release and have the windows icon Windows tab selected. If that tab is not selected, click that tab.
- Click Download (msi).
Open Windows Explorer/File Explorer.¶
Double-click the .msi file.¶
Follow the MongoDB Community Edition installation wizard.¶
The wizard steps you through the installation of MongoDB and MongoDB Compass.
You can choose either the Complete or Custom setup type. 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.
Starting in MongoDB 4.0, you can, by default, configure and start MongoDB as a service during the install, and the MongoDB service is started upon successful installation.
- If you choose not to configure MongoDB as a service, uncheck the Install MongoD as a Service.
- If you choose to configure MongoDB as a service, you can:
- Specify to run the service as one of the following users:
- Network Service user; 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 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.
- For an existing local user account, specify a period (i.e.
- Specify the Service Name. If you already have a service with the specified name, you must choose another name.
- 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. - 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.
- Specify to run the service as one of the following users:
You may install MongoDB MongoDB Community Edition unattended on Windows
from the command line using msiexec.exe.
Download MongoDB Community Edition.¶
- Open a web browser and visit the MongoDB Download Center.
- The Download Center should display the Current Stable Release and have the windows icon Windows tab selected. If that tab is not selected, click that tab.
- Click Download (msi).
Run the Windows Installer from the Windows Command Interpreter.¶
To install all MongoDB binaries, including MongoDB Compass, to the
default installation directory, go to the directory containing the
.msi installation binary and invoke:
To specify a different installation location for the executables,
add the INSTALLLOCATION value.
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:
To install only the MongoDB utilities, invoke:
If you do not wish to install
MongoDB Compass
at this time, include the SHOULD_INSTALL_COMPASS="0" argument.
Start MongoDB Community Edition from the Command Interpreter¶
Create database and log directories.¶
MongoDB requires a data directory to store all
data. MongoDB’s default data directory path is the absolute path
\data\db on the drive from which you start MongoDB.
Invoke the following command in the Command Interpreter to create these directories:
Note
The quotations marks matter when creating more than one directory path at the same time.
Start your MongoDB database.¶
To start MongoDB, invoke mongod.exe.
Example
From the Command Interpreter:
The --dbpath option points to your
database directory.
Note
If your path includes spaces, enclose the entire path in double quotes:
If the MongoDB database server is running correctly, the Command Interpreter displays:
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:
- Click Private Networks, such as my home or work network.
- Click Allow access.
To learn more about security and MongoDB, see the Security Documentation.
Start 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.
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:
Start the MongoDB service.¶
Close all other command prompts, then invoke the following command:
Verify that MongoDB has started successfully.¶
Check your MongoDB log file for the following line:
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.
Stop MongoDB Community 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:
Remove MongoDB Community Edition as a Windows Service¶
To remove the MongoDB service, first stop the service and then run the following command: