Section 4: Installation & Setup

πŸͺŸ Install MongoDB on Windows

Complete step-by-step guide to install MongoDB Community Edition on Windows 10/11 - From download to first query in 15 minutes!

πŸ“– Meet Rahul - The Curious Developer

πŸ‘¨β€πŸ’» Rahul's Journey

Rahul is a 2nd-year engineering student who just learned about NoSQL databases in class. Excited to try MongoDB, he tried to install it but got stuck with confusing tutorials and error messages. πŸ˜“

❌ Common Problems Students Face:
  • "MongoDB won't start - Command not found"
  • "Port 27017 is already in use"
  • "Access denied - Run as Administrator"
  • "The system cannot find the path specified"
  • Complex installation tutorials with missing steps

After 3 hours of frustration, Rahul found this complete, beginner-friendly guide. Within 15 minutes, he had MongoDB running and executed his first query! πŸŽ‰

βœ… What You'll Learn:
  • Download correct MongoDB version for Windows
  • Install with MongoDB Compass (GUI tool)
  • Configure environment variables
  • Start MongoDB as Windows Service
  • Run your first queries
  • Fix common installation errors

πŸš€ By the end of this guide, you'll have MongoDB fully running on your Windows machine!

πŸ’» System Requirements

πŸ“‹ Before You Start

Make sure your Windows PC meets these minimum requirements. Don't worry - most modern PCs easily exceed these!

πŸͺŸ
Operating System
Windows 10/11
64-bit edition (Server 2019+ for production)
🧠
RAM (Memory)
4 GB+
8 GB recommended for better performance
πŸ’Ύ
Disk Space
5 GB+
For MongoDB installation + data
⚑
Processor
64-bit
x86-64 architecture (Intel/AMD)
⚠️ Important Notes
  • MongoDB does NOT support 32-bit Windows
  • Windows 7 is no longer supported (upgrade to Windows 10/11)
  • You'll need Administrator privileges to install
  • Make sure no antivirus blocks the installation

🎯 Choose Your Installation Method

πŸ’‘ Recommended for Beginners

We recommend the MSI Installer with MongoDB Compass - it's the easiest way with a visual interface!

πŸ“¦
MSI Installer
Recommended for beginners
πŸ“
ZIP Archive
Manual setup required
🍫
Chocolatey
For package manager users
βœ“ MSI Installer Selected

The MSI installer automatically sets up MongoDB as a Windows Service, installs MongoDB Compass GUI tool, and configures everything for you. Perfect for learning!

⬇️ Download MongoDB Community Edition

MongoDB 8.0 Community Edition

Latest stable version for Windows

Download MongoDB 8.0

πŸ“¦ File size: ~400 MB | ⚑ Includes MongoDB Compass GUI

Latest version: 8.0 (Released 2024)

πŸ“ Download Instructions
  1. Click the download button above
  2. On MongoDB website, select:
    • Version: 8.0 (current)
    • Platform: Windows
    • Package: msi
  3. Click "Download" button
  4. Wait for download to complete (~400 MB)
  5. File will be: mongodb-windows-x86_64-8.0.x.msi
πŸ–ΌοΈ
MongoDB Download Page Screenshot

πŸ› οΈ Installation Steps

⚠️ Before Installation

Close these applications: Any antivirus software, Windows Defender (temporarily), and ensure you have Administrator privileges.

1

Run the Installer

Double-click the downloaded .msi file

Locate the downloaded file in your Downloads folder: mongodb-windows-x86_64-8.0.x.msi

Right-click β†’ Run as Administrator

πŸ–ΌοΈ
Right-click MSI file β†’ Run as Administrator
πŸ’‘ Pro Tip

If you see "Windows protected your PC", click "More info" then "Run anyway". MongoDB is safe!

2

Welcome Screen

Accept license and begin setup

You'll see the MongoDB Server Setup Wizard. Follow these:

  1. Click "Next" on welcome screen
  2. Check "I accept the terms"
  3. Click "Next"
πŸ–ΌοΈ
MongoDB Setup Wizard - Welcome & License
3

Choose Setup Type

Select "Complete" installation

You'll see two options:

  • Complete (Recommended): Installs everything including MongoDB Compass
  • Custom: For advanced users who want to choose components

βœ“ Select "Complete" and click "Next"

Default Installation Path: C:\Program Files\MongoDB\Server\8.0\
πŸ–ΌοΈ
Choose Setup Type: Select "Complete"
4

Service Configuration

Most important step!

This screen configures how MongoDB runs on your system.

βœ… Recommended Settings (Keep Defaults)
  • β˜‘ Run service as Network Service user (recommended)
  • Service Name: MongoDB
  • Data Directory: C:\Program Files\MongoDB\Server\8.0\data\
  • Log Directory: C:\Program Files\MongoDB\Server\8.0\log\
⚠️ Important

DO NOT uncheck "Install MongoDB as a Service" - This ensures MongoDB starts automatically when you boot Windows!

πŸ–ΌοΈ
Service Configuration Screen - Keep Defaults

After reviewing, click "Next"

5

Install MongoDB Compass

Visual GUI tool for MongoDB

MongoDB Compass is a beautiful GUI tool to visualize and interact with your data. Perfect for beginners!

βœ… Recommended

β˜‘ Check "Install MongoDB Compass" - It's free and makes learning much easier!

βœ“ With Compass
  • Visual interface
  • Easy data browsing
  • Query builder
  • Performance insights
Without Compass
  • Command line only
  • Harder to visualize
  • Manual queries
  • Text-based output
πŸ–ΌοΈ
Install MongoDB Compass - Check the box

Click "Next" to continue

6

Begin Installation

Grab a coffee! β˜• This takes 5-10 minutes

Review your settings and click "Install"

⏱️
Installation Progress

This typically takes 5-10 minutes

Installing...
πŸ“‹ What's Being Installed?
  • MongoDB Server: The core database engine
  • MongoDB Shell (mongosh): Command-line interface
  • MongoDB Compass: Visual GUI application
  • Windows Service: Auto-start configuration
  • Sample databases: Practice data (optional)
πŸ–ΌοΈ
Installation Progress Bar
⚠️ If Installation Hangs

If installation gets stuck on "Installing MongoDB Compass":

  1. Don't close the installer!
  2. It might take 10-15 minutes on slower connections
  3. It's downloading Compass from the internet
  4. Check your internet connection
7

Installation Complete!

Almost there! πŸŽ‰

When you see "Completed the MongoDB Server Setup Wizard":

  1. Click "Finish"
  2. MongoDB Compass might open automatically
  3. If not, find it in Start Menu
πŸŽ‰ Success!

MongoDB is now installed on your Windows machine! The service is running in the background.

πŸ–ΌοΈ
Installation Complete Screen

βœ… Verify Installation

πŸ’‘ 3 Ways to Verify

Let's make sure everything is working correctly. Try all three methods!

Method 1: Check Windows Service

Windows Services - Verify MongoDB is Running
1. Press Windows + R
2. Type: services.msc
3. Press Enter
4. Look for "MongoDB" in the list
5. Status should be "Running"
πŸ–ΌοΈ
Windows Services - MongoDB Running

Method 2: Command Line Test

CMD / PowerShell - Check MongoDB Version
# Open Command Prompt or PowerShell
# Type this command:

mongod --version

# You should see output like:
# db version v8.0.x
# Build Info: ...
# OpenSSL version: ...
⚠️ If Command Not Found

If you get "mongod is not recognized", you need to add MongoDB to your PATH. See troubleshooting section below.

Method 3: MongoDB Compass

Open MongoDB Compass:

  1. Search for "MongoDB Compass" in Windows Start Menu
  2. Click to open
  3. You should see connection screen with mongodb://localhost:27017
  4. Click "Connect"
  5. If connection succeeds, MongoDB is running! πŸŽ‰
πŸ–ΌοΈ
MongoDB Compass - Connection Screen

βœ“ Installation Verification Checklist

MongoDB Service is running - Check in services.msc
mongod command works - Run mongod --version in CMD
MongoDB Compass opens - Search in Start Menu
Connection successful - Connect to localhost:27017 in Compass
Can see default databases - admin, config, local should appear

πŸš€ Your First MongoDB Commands

πŸŽ‰ Congratulations!

MongoDB is installed and running. Let's execute your first database commands!

Step 1: Open MongoDB Shell (mongosh)

Open CMD/PowerShell and run mongosh
# In Command Prompt or PowerShell:
mongosh

# You'll see something like:
# Current Mongosh Log ID: ...
# Connecting to: mongodb://127.0.0.1:27017
# Connected to MongoDB version 8.0.x
# test>

Step 2: Create Your First Database

Create "myFirstDB" database
# Switch to new database (creates it automatically)
use myFirstDB

# Output: switched to db myFirstDB

Step 3: Insert Your First Document

Add a document to "students" collection
// Insert your first student
db.students.insertOne({
  name: "Rahul Kumar",
  age: 20,
  course: "Computer Science",
  marks: 85
})

// Output:
// {
//   acknowledged: true,
//   insertedId: ObjectId("...")
// }

Step 4: Query Your Data

Find all students
// Find all documents in students collection
db.students.find()

// Output: Shows the document you just inserted!
// {
//   _id: ObjectId("..."),
//   name: "Rahul Kumar",
//   age: 20,
//   course: "Computer Science",
//   marks: 85
// }

Step 5: Add More Documents

Insert multiple students at once
// Insert many documents
db.students.insertMany([
  {
    name: "Priya Sharma",
    age: 21,
    course: "Data Science",
    marks: 92
  },
  {
    name: "Amit Patel",
    age: 22,
    course: "Computer Science",
    marks: 78
  },
  {
    name: "Sneha Reddy",
    age: 20,
    course: "AI & ML",
    marks: 88
  }
])

// Output:
// {
//   acknowledged: true,
//   insertedIds: {
//     '0': ObjectId("..."),
//     '1': ObjectId("..."),
//     '2': ObjectId("...")
//   }
// }

Step 6: Try Some Queries

Filter and sort your data
// Find students with marks > 80
db.students.find({ marks: { $gt: 80 } })

// Find and sort by marks (descending)
db.students.find().sort({ marks: -1 })

// Count total students
db.students.countDocuments()

// Find one specific student
db.students.findOne({ name: "Priya Sharma" })
πŸŽ‰ Amazing Work!

You just created a database, inserted documents, and ran queries. You're officially a MongoDB user now! πŸš€

πŸ”§ Troubleshooting Common Issues

⚠️ Stuck? Don't Worry!

Here are solutions to the most common Windows installation problems.

❌
'mongod' is not recognized as an internal or external command
β–Ό

Problem: MongoDB is not in your system PATH.

Solution - Add MongoDB to PATH:

  1. Press Windows + R
  2. Type: sysdm.cpl and press Enter
  3. Click "Advanced" tab
  4. Click "Environment Variables"
  5. Under "System variables", find and select "Path"
  6. Click "Edit"
  7. Click "New"
  8. Add: C:\Program Files\MongoDB\Server\8.0\bin
  9. Click OK on all windows
  10. Close and reopen Command Prompt/PowerShell
Verify PATH is set
# Close and reopen CMD, then run:
mongod --version

# Should now work!
🚫
MongoDB service won't start / Failed to start
β–Ό

Common Causes:

  • Port 27017 is already in use
  • Data directory doesn't exist or no permissions
  • Another MongoDB instance is running

Solution 1 - Check Port:

Check what's using port 27017
# In Command Prompt (as Administrator):
netstat -ano | findstr :27017

# If something is using port, kill it:
taskkill /PID [process_id] /F

Solution 2 - Recreate Data Directory:

Create data folder with permissions
# In PowerShell (as Administrator):
mkdir "C:\Program Files\MongoDB\Server\8.0\data"
mkdir "C:\Program Files\MongoDB\Server\8.0\log"

# Then restart MongoDB service:
net stop MongoDB
net start MongoDB
πŸ”’
Access Denied / Permission Errors
β–Ό

Problem: You don't have Administrator privileges.

Solution:

  1. Right-click on Command Prompt or PowerShell
  2. Select "Run as Administrator"
  3. If still issues, disable antivirus temporarily
  4. Make sure Windows Defender isn't blocking MongoDB
⚠️ Antivirus Interference

Some antivirus programs block MongoDB. Add MongoDB folder to exceptions: C:\Program Files\MongoDB\

πŸ’Ύ
MongoDB Compass won't connect
β–Ό

Problem: Can't connect to localhost:27017

Solutions:

1. Verify MongoDB Service is Running:

Check MongoDB status
# PowerShell:
Get-Service MongoDB

# Status should be "Running"
# If stopped, start it:
Start-Service MongoDB

2. Check Connection String:

Make sure you're using correct connection string:

mongodb://localhost:27017

OR

mongodb://127.0.0.1:27017

3. Firewall Issues:

Add MongoDB to Windows Firewall exceptions if blocked.

πŸ“¦
Installation hangs at "Installing MongoDB Compass"
β–Ό

Problem: Installer stuck downloading Compass.

Solutions:

  1. Be Patient: It can take 10-15 minutes on slow connections
  2. Check Internet: Installer downloads Compass from internet
  3. Alternative: Cancel installer, reinstall WITHOUT Compass checkbox
  4. Manual Install: Download Compass separately from MongoDB Compass Download Page

🎯 What's Next?

πŸŽ‰ You Did It!

MongoDB is installed and running on your Windows machine. Here's what to learn next!

🧭

Install MongoDB Compass

Learn to use the visual GUI tool for MongoDB

Learn Compass β†’
πŸ’»

MongoDB Shell (mongosh)

Master the command-line interface

Learn mongosh β†’
πŸ“š

MongoDB Basics

Start learning CRUD operations

Start Learning β†’

πŸ“š Recommended Learning Path

  1. Databases & Collections - Understand basic structure
  2. Documents & BSON - Learn data format
  3. CRUD Operations - Create, Read, Update, Delete
  4. Query Operators - Filter and find data
  5. Indexing - Optimize performance