Day 21: Introduction to MongoDB & Installing MongoDB Compass
1. What is MongoDB?
MongoDB is a NoSQL database.
That means it does not store data in rows and columns like MySQL or PostgreSQL. Instead, it stores data in documents (like JSON objects) inside collections.
👉 Think of it like this:
Database = a big folder
Collection = a smaller folder inside the big one
Document = a JSON file stored inside the folder
Example document in MongoDB:
{
"title": "My First Blog",
"author": "Payal",
"tags": ["Node.js", "MongoDB"],
"likes": 20
}
This looks very similar to a JavaScript object. That’s why MongoDB is a favorite choice when working with Node.js — because both use JSON format.
2. Why use MongoDB? (Real-life example)
Imagine you are building a blog website:
Each blog has a title, description, author, tags, likes, and comments.
Some blogs may have comments, some may not.
Some blogs may have an image, some may not.
If you use a SQL database, you would have to create many tables with fixed columns.
But with MongoDB, you can store flexible data like this:
{
"title": "First Blog",
"author": "Payal",
"tags": ["Tech", "Education"],
"likes": 5,
"comments": [
{ "user": "Riya", "message": "Nice article!" },
{ "user": "Amit", "message": "Very helpful" }
]
}
👉 Here, comments are stored as an array of objects inside the blog. This flexibility is the biggest advantage of MongoDB.
3. Installing MongoDB
Now let’s install MongoDB step by step.
Step 1: Download MongoDB
Go to official website: https://www.mongodb.com/try/download/community
Select:
Version: Current version (not legacy)
Platform: Windows / macOS / Linux (according to your OS)
Package: MSI (for Windows) or TGZ/PKG (for Mac/Linux)
Download and install.
Step 2: Install MongoDB as a service
During installation, choose:
“Run as Network Service User” (recommended).
Make sure MongoDB Compass option is checked if available.
MongoDB will now run in the background as a Windows service (or Mac/Linux service).
4. What is MongoDB Compass?
MongoDB Compass is the official GUI (Graphical User Interface) for MongoDB.
👉 Think of it like phpMyAdmin for MySQL.
With Compass, you can:
Connect to your database
Create databases and collections
Insert, update, and delete documents
Run queries visually (without writing long commands)
5. Installing MongoDB Compass
If you didn’t install it during MongoDB installation:
Download according to your OS.
Install it just like any normal software.
6. Connecting to MongoDB using Compass
Open MongoDB Compass.
In the connection string box, type:
mongodb://localhost:27017
Here:
localhost = means MongoDB is running on your local computer.
27017 = default port of MongoDB.
- Click Connect.
✅ You are now connected to your local MongoDB server.
7. First Database and Collection (Example)
Create a Database
Click Create Database
Database name:
blogAppCollection name:
posts
Insert a Document
Insert this document:
{
"title": "Hello MongoDB",
"author": "Payal",
"likes": 10
}
Click Insert. 🎉
You just created your first MongoDB database and document.
8. Real-life Example: Storing Notes
Let’s say we are making a Notes app.
Each note will have:
Title
Description
Date
In MongoDB Compass → Insert document:
{
"title": "Shopping List",
"description": "Buy milk, bread, and eggs",
"date": "2025-08-19"
}
👉 Advantage: Tomorrow, if you want to add a priority field, you can just add it to some notes without changing old ones.
9. Summary
MongoDB is a NoSQL database that stores data in documents (JSON format).
It is flexible, perfect for modern applications.
You installed MongoDB server + MongoDB Compass.
You learned how to:
Connect to MongoDB with Compass
Create a database and collection
Insert documents (like blog posts or notes)
🔔 Stay Connected
If you found this article helpful and want to receive more such beginner-friendly and industry-relevant Node JS notes, tutorials, and project ideas — 📩 Subscribe to our newsletter by entering your email below.
And if you're someone who wants to prepare for tech interviews while having a little fun and entertainment, 🎥 Don’t forget to subscribe to my YouTube channel – Knowledge Factory 22 – for regular content on tech concepts, career tips, and coding insights!
Stay curious. Keep building. 🚀

