Skip to main content

Command Palette

Search for a command to run...

Day 21: Introduction to MongoDB & Installing MongoDB Compass

Published
4 min read
P
Hi there, tech enthusiasts! I'm a passionate Software Developer driven by a love for continuous learning and innovation. I thrive on exploring new tools and technologies, pushing boundaries, and finding creative solutions to complex problems. What You'll Find Here On my Hashnode blog, I share: 🚀 In-depth explorations of emerging technologies 💡 Practical tutorials and how-to guides 🔧Insights on software development best practices 🚀Reviews of the latest tools and frameworks 💡 Personal experiences from real-world projects. Join me as we bridge imagination and implementation in the tech world. Whether you're a seasoned pro or just starting out, there's always something new to discover! Let’s connect and grow together! 🌟

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

  1. Go to official website: https://www.mongodb.com/try/download/community

  2. Select:

    • Version: Current version (not legacy)

    • Platform: Windows / macOS / Linux (according to your OS)

    • Package: MSI (for Windows) or TGZ/PKG (for Mac/Linux)

  3. 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:

  1. Go to: https://www.mongodb.com/try/download/compass

  2. Download according to your OS.

  3. Install it just like any normal software.


6. Connecting to MongoDB using Compass

  1. Open MongoDB Compass.

  2. In the connection string box, type:

mongodb://localhost:27017

Here:

  • localhost = means MongoDB is running on your local computer.

  • 27017 = default port of MongoDB.

  1. Click Connect.

✅ You are now connected to your local MongoDB server.


7. First Database and Collection (Example)

Create a Database

  1. Click Create Database

  2. Database name: blogApp

  3. Collection 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. 🚀

More from this blog

T

Technologies: Tools & Tips | Expert Guides on Latest Tech Tools

125 posts