How to Install and Use MongoDB on Windows
Step-by-step guide for beginners
Introduction
MongoDB is a popular NoSQL database used for storing JSON-like documents. If you’re a Windows user and want to start working with MongoDB, this guide is for you. We’ll walk through installation, setup, and basic usage.
Keywords:
MongoDB, Windows, NoSQL, MongoDB installation, MongoDB commands, MongoDB Compass, MongoDB shell, JSON database
Step 1: Download MongoDB for Windows
- Go to the official MongoDB download page: https://www.mongodb.com/try/download/community
- Choose the latest stable version.
- Select Windows as the operating system.
- Download the MSI installer.
- Direct download link
Step 2: Install MongoDB
- Run the downloaded MSI installer.
- Choose Complete setup when prompted.
- Make sure to select the option: "Install MongoDB as a Service".
- Also install MongoDB Compass (MongoDB’s GUI) if you want.
Step 3: Verify Installation
Open Command Prompt and type:
mongod --version
If installed correctly, you will see the MongoDB server version.
🔍 How to Check MongoDB Version Using mongod --version
To check which version of MongoDB is installed on your Windows system, open Command Prompt or PowerShell and type the following command:
mongod --version
✔️ This will display the version of the MongoDB server daemon (not the GUI or Compass).
🧾 Example Output:
db version v6.0.6
Build Info: {
"version": "6.0.6",
"gitVersion": "abcdef1234567890",
"openSSLVersion": "OpenSSL 1.1.1n 15 Mar 2022",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "windows",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
⚠️ If You Get an Error:
If you see this error:
'mongod' is not recognized as an internal or external command
It means MongoDB is not added to your system PATH. You can:
- Go to:
C:\Program Files\MongoDB\Server\version\bin
- Run
mongod.exe
directly from that folder - Or add that path to your System Environment Variables → PATH
Once added correctly, you’ll be able to use MongoDB commands from anywhere in the terminal.
Step 4: Start MongoDB Server
If you installed as a service, MongoDB should already be running. But you can manually start the MongoDB server like this:
"C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe"
(Adjust the path if you installed a different version)
Step 5: Open MongoDB Shell (mongosh)
To start using MongoDB, open another Command Prompt and type:
mongosh
This opens the MongoDB Shell where you can run commands.
Step 6: Basic MongoDB Commands
Create or Switch Database:
use mydatabase
Create Collection and Insert Data:
db.users.insertOne({ name: "Champak", age: 22 })
Find Data:
db.users.find()
Update Data:
db.users.updateOne({ name: "Champak" }, { $set: { age: 23 } })
Delete Data:
db.users.deleteOne({ name: "Champak" })
Step 7: Using MongoDB Compass (Optional)
MongoDB Compass is a graphical user interface (GUI) for MongoDB. It lets you visualize databases, collections, and documents easily.
- Open Compass from the Start Menu.
- For localhost connection, use:
mongodb://localhost:27017
- Click "Connect" to see your databases.
Step 8: Setting MongoDB Path (Optional)
If you want to run mongod
and mongosh
from any directory in Command Prompt, add MongoDB’s bin
folder to your system PATH.
Steps:
- Right-click on "This PC" → Properties → Advanced system settings → Environment Variables.
- Under "System Variables", find "Path" → Click Edit → Add:
C:\Program Files\MongoDB\Server\7.0\bin
Common Errors and Fixes
- Port already in use: Stop any other services running on port 27017.
- Command not recognized: Ensure you added MongoDB to your PATH.
- Cannot connect with Compass: Make sure MongoDB server is running.
Conclusion
Congratulations! You’ve successfully installed and run MongoDB on your Windows system. Now you’re ready to start building NoSQL applications with MongoDB.
Happy Coding!
🧩 What is a MongoDB Cluster?
A MongoDB Cluster is a group of MongoDB servers that work together to store and manage your data. Clusters help with high availability, data replication, and horizontal scaling.
There are two main types of MongoDB clusters:
- Replica Set: A group of MongoDB servers that keep copies (replicas) of the same data. If one server fails, another takes over automatically. This ensures data safety and uptime.
- Sharded Cluster: A setup where data is split across multiple servers (called shards). It’s used when your data is too large for a single machine and needs to be scaled horizontally.
When you use MongoDB Atlas (MongoDB’s cloud service), it creates and manages clusters for you. You don’t have to worry about setup, security, or scaling — just connect to the cluster and start using it!
Example: The connection string below connects your app to a cloud MongoDB cluster:
mongodb+srv://username:password@cluster0.mongodb.net/myDatabase
Clusters are the backbone of MongoDB's ability to handle large-scale, high-performance applications.
0 Comments