News & Updates

How to Install MongoDB on Windows: Step-by-Step Guide

By Sofia Laurent 179 Views
how to install mongodb windows
How to Install MongoDB on Windows: Step-by-Step Guide

Setting up MongoDB on a Windows machine provides a reliable path to local development and testing. This guide walks through each step, from downloading the official package to running your first database instance. You will learn how to configure the data directory, add MongoDB to your system path, and verify the installation with simple commands.

Downloading the MongoDB Community Edition

Begin by acquiring the latest stable release from the official MongoDB website. Navigate to the download center and select the version compatible with your Windows architecture, either 64-bit or ARM64. Choosing the correct MSI installer ensures a smooth integration with the Windows Installer service, handling file placement and registry entries automatically.

Selecting the Correct Installer

Download the MongoDB MSI package for Windows.

Verify the file checksum after download to confirm integrity.

Ensure your system meets the minimum requirements for the selected version.

Installing MongoDB Using the MSI Installer

Once the download completes, launch the MSI file and follow the installation wizard. The setup process allows you to choose between a complete installation or a custom configuration. Accepting the default settings is usually sufficient for most development environments, placing the binaries in the Program Files directory.

Completing the Setup

Review the license agreement and select "I Agree" to proceed.

Choose the installation location, typically the default path is recommended.

Opt to install MongoDB Compass, the graphical user interface, for easier management.

Configuring the Windows Service

For MongoDB to run automatically in the background, it must be installed as a Windows service. This step requires opening Command Prompt with administrative privileges. Executing the mongod.exe command with the --install argument registers the service, allowing the system to manage the database process independently of user login sessions.

Managing the Service

Command
Description
net start MongoDB
Starts the MongoDB service.
net stop MongoDB
Stops the MongoDB service.
sc delete MongoDB
Removes the service from Windows.

Setting the Data Directory and Path Variables

MongoDB requires a dedicated folder to store its database files. By default, it looks for C:\data\db , but this location might not suit your preferences. Creating this directory manually or specifying an alternative path during configuration prevents common startup errors related to missing directories.

Additionally, adding the MongoDB bin folder to your system's PATH environment variable is essential. This step allows you to execute mongo and mongod commands from any directory in the Command Prompt. Without this configuration, you would need to navigate to the installation directory every time you want to use the tools.

Starting MongoDB and Verifying the Installation

After the service is installed and the path is set, starting the database is straightforward. Running net start MongoDB in an elevated command prompt launches the instance. You should see a confirmation message indicating that the service started successfully, and the server is listening on the default port 27017.

Testing the Connection

Open a new command prompt window and type mongo to launch the MongoDB Shell. If the shell connects successfully and displays a prompt, the installation is complete. You can now create databases, insert documents, and begin exploring MongoDB's capabilities on your local Windows machine.

S

Written by Sofia Laurent

Sofia Laurent is a Senior Editor exploring design, lifestyle, and global trends. She blends editorial clarity with a refined point of view.