Installing MongoDB Community Edition on Windows
Prerequisites
Before installing MongoDB Community Edition on Windows, ensure your system meets the minimum requirements. MongoDB requires an x86-64 architecture and supports the following platforms:
- Windows 7 / Server 2008 R2
- Windows 8 / Server 2012 R2
- Windows 10 / Server 2016 and later versions
Additionally, Windows 2012 Server and Windows 10 require KB2999226 to provide support for Universal C runtime for Windows systems.
Production Considerations
In a production environment, consider annotating production documents before deploying MongoDB.
Alternative: MongoDB Atlas
You can also use a fully managed database service, MongoDB Atlas, launched on Microsoft’s cloud (Azure). Atlas allows you to configure everything from a free sandbox environment to global production clusters.
Setting Up a Free Cluster
To install MongoDB, use the Setup Wizard to install the binary files and the default configuration file.
Step 1: Download the MongoDB Community Edition
- Download the Installer (.msi) from the MongoDB Download Center.
- Select the “Server” option, then click the “MongoDB Community Server” option.
- In the Version drop-down list, select the latest version of MongoDB Server (4.0).
- In the OS drop-down list, select Windows 64-bit X64.
- In the Package drop-down list, select MSI.
- Click Download.
Step 2: Run the Installation Program
- From Windows Explorer / File Explorer, go to the directory where you downloaded the installer (.msi files).
- Double-click the .msi file.
Step 3: Follow the Installation Wizard
- Select the type of installation (recommended for most users) or Custom installation type.
- If you select “Custom” installation, you can specify the location and installation of the executable file.
- Services Configuration: from MongoDB 4.0, you can set MongoDB service during installation, or install only binary files.
- MongoDB service: The following are installed and configured MongoDB as a service.
- Starting MongoDB 4.0, you can configure during installation and start MongoDB as a service, and start the MongoDB service after successful installation.
Configuring MongoDB Service
- Select the MongoDB installed as a service.
- Run the service as Network Service user (default) or a local or domain user running the service.
- Specify the service name (default is MongoDB).
- Designate the data directory corresponding to -dbpath.
- If the directory does not exist, the installation program will create the directory and set the directory access service users.
- Specify the log directory, which corresponds to -logpath.
- If the directory does not exist, the installation program will create the directory and set the directory access service users.
Starting MongoDB
- If you install MongoDB service, start the service to start using MongoDB.
- To connect to the MongoDB instance, open a command interpreter with administrator privileges and run: “C: \ Program Files \ MongoDB \ Server \ 4.0 \ bin \ mongo.exe”
- For information about CRUD (create, read, update, delete) operations, see: Insert File, Polling, update files, Delete files
Community Edition Runs MongoDB from the Command Interpreter
- Create a database directory.
- Start the MongoDB database.
- Connect to MongoDB.
- For more information about connecting mongo.exe, see mongo Shell.
- For information about CRUD (create, read, update, delete) operations, see: Insert File, Polling, update files, Delete files
Starting/Stopping/Deleting MongoDB Service
- To start/restart MongoDB service, use the service console:
- From the service console, find the MongoDB service.
- Right-click the MongoDB service, and then click “Start.”
- To stop/pause MongoDB service, use the service console:
- From the service console, find the MongoDB service.
- Right-click the MongoDB service, and then click “Stop” (or “pause”).
- To delete MongoDB service, first use the service console to stop the service, then open the Windows command prompt as an administrator / interpreter (cmd.exe), and run the following command: sc.exe delete MongoDB
Adding Binary File to System Path
All absolute path command line examples in this tutorial are provided by MongoDB binaries. You can use C: \ ProgramFiles \ MongoDB \ Server \ 4.0 \ bin to your system path, then the full path to MongoDB binary omitted.
Translator’s Note
Wang Zihao, an American student, returned to China and is interested in studying the latest technologies, including blockchain development. His motto is “Stay hungry, stay foolish.”