installation
MongoDB Installation on Windows
Below is a step-by-step guide to install MongoDB on a Windows system:
Step 1: Download MongoDB Installer
- Go to the official MongoDB website: https://www.mongodb.com/try/download/community.
- Under the Community Server section, select:
- Version: Choose the latest stable version.
- Platform: Select "Windows".
- Package: Choose "MSI" (recommended for easier installation).
- Click Download.
Step 2: Run the MongoDB Installer
- Locate the downloaded
.msi
file and double-click to run it. - Follow the installation wizard:
- Accept the license agreement.
- Choose Complete setup type (recommended for most users).
- Optionally, you can customize the installation path (e.g.,
C:\Program Files\MongoDB\Server\<version>
).
- Check the box to install MongoDB Compass (a graphical interface for MongoDB, optional but recommended).
- Click Install and wait for the installation to complete.
Step 3: Set Up MongoDB Environment
-
Create the MongoDB data and log directories:
- Open Command Prompt as Administrator.
- Run the following commands:
md "C:\data\db"
md "C:\data\log" - These directories will store your MongoDB database files and logs.
-
Configure the MongoDB configuration file:
- Navigate to the MongoDB installation directory (e.g.,
C:\Program Files\MongoDB\Server\<version>\bin
). - Create a file named
mongod.cfg
in thebin
directory. - Add the following content to the file:
systemLog:
destination: file
path: C:\data\log\mongod.log
storage:
dbPath: C:\data\db
- Navigate to the MongoDB installation directory (e.g.,
Step 4: Install MongoDB as a Windows Service
- Open Command Prompt as Administrator.
- Run the following command to install MongoDB as a service:
"C:\Program Files\MongoDB\Server\<version>\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\<version>\bin\mongod.cfg" --install
- Start the MongoDB service:
net start MongoDB
- To stop the service, use:
net stop MongoDB
Step 5: Verify MongoDB Installation
- Open Command Prompt.
- Run the following command to connect to the MongoDB server:
"C:\Program Files\MongoDB\Server\<version>\bin\mongo.exe"
- If the connection is successful, you will see the MongoDB shell prompt (
>
).
Step 6: (Optional) Add MongoDB to System PATH
To make it easier to run MongoDB commands from any directory:
- Open Environment Variables:
- Right-click on This PC > Properties > Advanced system settings > Environment Variables.
- Under System Variables, find and select
Path
, then click Edit. - Add the MongoDB
bin
directory path (e.g.,C:\Program Files\MongoDB\Server\<version>\bin
). - Click OK to save changes.
Step 7: Test MongoDB
- Open Command Prompt.
- Run the following commands:
mongo
- In the MongoDB shell, run:
If the document is inserted and retrieved successfully, your MongoDB installation is working correctly.
db.test.insertOne({ name: "MongoDB Test" })
db.test.find()
Step 8: Install MongoDB Compass (Optional)
If you didn’t install MongoDB Compass during the installation:
- Download MongoDB Compass from https://www.mongodb.com/try/download/compass.
- Run the installer and follow the steps to complete the installation.
- Launch MongoDB Compass and connect to your local MongoDB instance (
mongodb://localhost:27017
).
MongoDB Installation Guide
Below is a step-by-step guide to install MongoDB on Windows. You can also watch the video tutorial for a visual walkthrough:
Steps to Install MongoDB
- Download the MongoDB installer from the official website.
- Run the installer and follow the setup wizard.
- Set up the data and log directories.
- Configure MongoDB as a Windows service.
- Verify the installation by connecting to the MongoDB shell.
You’ve successfully installed MongoDB on Windows! 🎉