📘 Who Is This MongoDB Guide For?
This guide is for you if you’ve heard the word “MongoDB” many times, but still feel it’s a bit “foggy” in your head. Maybe you are:
- 💼 An IT Support / System Admin who wants to understand modern apps
- 🧑💻 A beginner web developer learning MERN / MEAN stack
- 🎓 A student who only knows SQL and wants to understand NoSQL
- Or simply curious: “Why are so many companies using MongoDB?”
In this article, we’ll go through MongoDB step-by-step in a friendly, practical way. If you read it carefully, you’ll understand the core concepts and feel comfortable enough to start building a small project.
1️⃣ What Is MongoDB in Simple Words?
Short answer: MongoDB is a NoSQL document database.
Instead of storing data in tables and rows like SQL databases, MongoDB stores data in
documents that look very similar to JSON objects.
Example of one MongoDB document:
{
_id: ObjectId("673844..."),
name: "Ali Khan",
role: "IT Support Engineer",
skills: ["Windows", "Networking", "MDM"],
active: true,
profile: {
city: "Dammam",
country: "Saudi Arabia"
}
}
Instead of thinking in tables and joins, you think in collections and documents. A collection is like a table, and a document is like a row – but more flexible.
2️⃣ SQL vs MongoDB – Quick Mental Model
Here is a simple way to map your SQL knowledge to MongoDB:
- Database (SQL) → Database (MongoDB)
- Table → Collection
- Row → Document
- Column → Field
- JOIN → Embedding or Reference
- Primary Key → _id (auto-generated unique id)
In SQL, you must define a fixed schema first (columns, data types). In MongoDB, documents in the same collection can have slightly different structures (MongoDB is schema flexible).
3️⃣ Core Building Blocks of MongoDB
🔹 Database
A database is a logical container in MongoDB that holds collections. You can create multiple databases, for example:
it_support_dbinventory_dbblog_platform_db
🔹 Collection
A collection is like a table in SQL, but without a fixed schema. Example collections:
usersticketsdeviceslogs
🔹 Document
A document is a JSON-like object stored inside a collection.
Each document has a unique _id field.
Example ticket document in an IT Support system:
{
_id: ObjectId("6738a5..."),
title: "User cannot print to network printer",
priority: "High",
status: "Open",
createdAt: ISODate("2025-11-16T10:25:00Z"),
requester: {
name: "Mohammed",
department: "Accounts"
},
tags: ["printer", "network", "branch1"]
}
🔹 BSON
Internally, MongoDB stores data in BSON (Binary JSON).
You don’t have to worry too much about this – you still read and write JSON-style data,
but BSON allows extra types like Date, ObjectId, etc.
4️⃣ When Is MongoDB a Good Choice?
MongoDB shines in scenarios like:
- 🌐 Web and mobile apps where data structure can evolve over time
- 📱 User profiles, activity logs, comments, chat messages
- 🛒 E-commerce products with flexible attributes (color, size, specs)
- 📊 Event logging and analytics
Typical reasons teams choose MongoDB:
- Flexible schema – easy to add new fields without migrations
- Good for large-scale read/write workloads
- Easy integration with Node.js, Express, React (MERN)
- Managed cloud service (MongoDB Atlas) with backups & monitoring
5️⃣ Getting Started – How to Use MongoDB (Step by Step)
Step 1 – Choose Where to Run MongoDB
You have two main options:
-
MongoDB Atlas (Cloud, recommended for beginners)
You create a free account, spin up a free cluster, and connect via connection string. -
Local Installation
Install MongoDB Community Server on your Windows / Linux / Mac and run it locally.
Step 2 – Use a GUI: MongoDB Compass
MongoDB offers a free GUI tool called Compass. It allows you to:
- Browse databases and collections visually
- Run queries without the terminal
- See documents in a formatted view
- Visualize schema and create indexes
Step 3 – Connect to the Database
In Atlas, you’ll get a connection string like:
mongodb+srv://username:password@cluster0.abcd123.mongodb.net/
You can use this URL in:
- MongoDB Compass
- Your Node.js / Python application
- VS Code extensions, etc.
6️⃣ Basic CRUD Operations in MongoDB
CRUD means Create, Read, Update, Delete.
We’ll use a simple collection called users.
🔹 Create – insertOne() and insertMany()
Insert a single user:
db.users.insertOne({
name: "Rabby",
role: "IT Support Specialist",
skills: ["Windows", "MDM", "Networking"],
active: true
});
Insert multiple users:
db.users.insertMany([
{ name: "Sara", role: "Developer", active: true },
{ name: "Omar", role: "Network Engineer", active: false }
]);
🔹 Read – find()
Get all users:
db.users.find();
Get only active users:
db.users.find({ active: true });
Query by a condition (age greater than 25):
db.users.find({ age: { $gt: 25 } });
🔹 Update – updateOne(), updateMany()
Set a user as inactive:
db.users.updateOne(
{ name: "Omar" },
{ $set: { active: false } }
);
Add a new skill to a user:
db.users.updateOne(
{ name: "Rabby" },
{ $push: { skills: "SQL Server" } }
);
🔹 Delete – deleteOne(), deleteMany()
Delete a specific user:
db.users.deleteOne({ name: "Sara" });
Delete all inactive users:
db.users.deleteMany({ active: false });
7️⃣ Embedding vs Referencing (Relationships)
MongoDB does not have classic SQL joins by default, but you can model relationships in two main ways:
Option 1 – Embedding (Nested Documents)
Example: Order with embedded items:
{
_id: ObjectId("6738..."),
customerName: "Ali",
items: [
{ product: "Keyboard", qty: 1, price: 80 },
{ product: "Mouse", qty: 2, price: 40 }
],
total: 160
}
Good for data that is usually read together and not too large.
Option 2 – Referencing (Store IDs)
Example: Store userId in the ticket document:
{
_id: ObjectId("6738..."),
title: "VPN not connecting",
userId: ObjectId("66fa...")
}
Your application then looks up the user in the users collection.
This is closer to the SQL way of thinking.
8️⃣ Indexes – Making Queries Fast
Just like in SQL, MongoDB uses indexes to speed up queries.
If you frequently search by email, you should create an index on it.
Create an index on email:
db.users.createIndex({ email: 1 });
Without indexes, queries on large collections can become slow. For small projects, you may not feel it, but for bigger apps it’s critical.
9️⃣ Security & Best Practices (Beginner Level)
- ✅ Always use a strong password for your MongoDB user
- ✅ Do not expose your MongoDB port directly to the public internet
- ✅ Use IP allowlist in Atlas or firewall rules on your server
- ✅ Store the connection string in environment variables, not hard-coded in Git
- ✅ Take regular backups (Atlas can automate this for you)
🔟 How to Practice MongoDB Daily (Simple Routine)
Here’s a simple practical plan you can follow in 20–30 minutes per day:
- Create a small project idea – e.g. “IT Asset Inventory” or “Personal Task Manager”.
- Design 2–3 collections:
users,assets,ticketsetc. - Insert sample data from real life (your devices, tickets, tasks).
- Practice queries:
- Find all assets assigned to you.
- Find all open tickets.
- Update status to “Closed” when resolved.
- Add a new field later (e.g.
warrantyExpiry) and see how flexible MongoDB is.
✅ Final Thoughts – MongoDB as a Tool in Your Stack
MongoDB is not “better” or “worse” than SQL – it’s simply a different tool. When you understand both, you can choose the right one for the right problem.
As a beginner, focus on:
- Understanding documents, collections, and CRUD
- Practicing simple queries in Compass or the shell
- Connecting a small Node/Express app to your MongoDB database
Once you get comfortable, you’ll see why so many modern applications rely on MongoDB to handle flexible, fast-changing data.