Easy MongoDB Installation Guide for Windows
Beginner-friendly step-by-step tutorial to install MongoDB, MongoDB Compass, and test your first database.
What is MongoDB?
MongoDB is a popular NoSQL database used to store data in JSON-like documents. It is widely used in backend development, MERN stack projects, APIs, authentication systems, and real-time web applications.
{
"name": "Harsh",
"age": 21,
"course": "MERN Stack"
}
Why Use MongoDB?
- Easy to learn for beginners
- Stores data in flexible JSON-like format
- Works perfectly with Node.js and Express.js
- Best choice for MERN stack development
- Fast, scalable, and developer-friendly
Step 1: Download MongoDB
First, open the official MongoDB Community Server download page.
Download MongoDB Community Server
Select the following options:
| Option | Select |
|---|---|
| Version | Latest Stable |
| Platform | Windows |
| Package | MSI |
Step 2: Install MongoDB
After downloading the MSI file, double-click on it and follow these simple steps:
- Click Next
- Accept the license agreement
- Select Complete Installation
- Keep Install MongoDB as a Service checked
- Keep Install MongoDB Compass checked
- Click Install
- Click Finish
What is MongoDB Compass?
MongoDB Compass is the official GUI tool for MongoDB. It helps you create databases, collections, and documents visually without using many commands.
- Create databases easily
- Insert and edit documents
- View collections
- Run MongoDB queries
- Manage data visually
Step 3: Verify MongoDB Installation
Open Command Prompt by pressing Windows + R, type cmd, and press Enter.
Now run this command:
mongosh
If MongoDB is installed correctly, you will see:
test>
Step 4: Connect MongoDB Compass
Search for MongoDB Compass in Windows search and open it.
Use this connection string:
mongodb://localhost:27017
Click on Connect. Now MongoDB Compass is connected to your local MongoDB server.
Step 5: Create Your First Database
Inside MongoDB Compass, click on Create Database.
| Field | Value |
|---|---|
| Database Name | testdb |
| Collection Name | users |
Click Create Database. Your first MongoDB database is ready.
Step 6: Insert Your First Document
Open the users collection and click:
Paste this sample data:
{
"name": "Harsh",
"age": 21,
"city": "Delhi"
}
Click Insert. Your first document is now saved in MongoDB.
Step 7: Test MongoDB Using Commands
Open Command Prompt and run:
mongosh
Now run these commands one by one:
use testdb
db.users.insertOne({
name: "Harsh",
age: 21
})
db.users.find()
If your data appears on screen, MongoDB is working perfectly.
Common MongoDB Errors and Fixes
1. mongosh is not recognized
This error means MongoDB Shell path is not added to Environment Variables.
Add this path:
C:\Program Files\MongoDB\Server\8.0\bin
After adding the path, restart Command Prompt and try again.
2. Connection Refused Error
This error usually means MongoDB service is not running.
Run Command Prompt as Administrator and type:
net start MongoDB
Install MongoDB with Node.js
If you are learning backend development or MERN stack, install Mongoose in your Node.js project.
npm install mongoose
Simple MongoDB connection example:
const mongoose = require("mongoose");
mongoose.connect("mongodb://127.0.0.1:27017/testdb")
.then(() => console.log("MongoDB Connected"))
.catch(err => console.log(err));
Final Thoughts
Installing MongoDB on Windows is very easy when you follow the correct steps. After installation, you can start learning CRUD operations, Mongoose, Express.js integration, authentication systems, APIs, and MERN stack development.