✍️

MongoDB Installation Guide for Windows – Easy Setup Tutorial for Beginners

Easy MongoDB Installation Guide for Windows | Beginner Tutorial

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.

Example MongoDB Document:
{
  "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:

  1. Click Next
  2. Accept the license agreement
  3. Select Complete Installation
  4. Keep Install MongoDB as a Service checked
  5. Keep Install MongoDB Compass checked
  6. Click Install
  7. Click Finish
Important: Always keep “Install MongoDB as a Service” checked. This allows MongoDB to start automatically when your computer starts.

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:

Add Data → Insert Document

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.

Conclusion: MongoDB is one of the best databases for modern web development and is a must-learn tool for backend and MERN stack developers.

Official Resources

❮ Previous Next ❯