MongoDB Introduction

What Is MongoDB?
MongoDB is an open-source NoSQL document database. It stores each record as a document—a JSON-like object that can hold nested fields and arrays—instead of a row in a fixed table.
Hierarchy:
database → collection → document → field
Storage: BSON (binary JSON)
Query: find(), update methods, aggregation — not SQL Documents live in collections; collections live in a database. This page is the gateway to the MongoDB tutorial—deeper topics have their own pages.
Why Use MongoDB?
MongoDB was built for large web apps where rigid tables slowed change and scale. The name comes from “humongous.”
| Need | How MongoDB helps |
|---|---|
| Flexible data | Documents in one collection do not need the same fields |
| Nested objects | Related data can live in one document instead of many joined tables |
| Horizontal scale | Sharding spreads data across servers |
| Fast iteration | Schema can evolve without heavy migrations for every change |
How MongoDB Organizes Data
Each level contains many of the next. Keep this hierarchy in mind.
| Level | What it is | Example |
|---|---|---|
| Database | Container for related collections | shop |
| Collection | Group of similar documents | users, orders |
| Document | One record (field–value pairs) | One user profile |
| Field | A key inside a document | email, age |
_id | Unique ID for every document | Auto-generated ObjectId |
Cheat sheet — tools
| Tool | Role |
|---|---|
mongod | Database server process |
mongosh | Interactive shell used in this tutorial |
| Drivers | Connect apps (Node.js, Python, Java, …) |
| Compass | Desktop GUI for browsing data |
| Atlas | Managed MongoDB in the cloud |
What Does a Document Look Like?
One document from a users collection:
{
_id: ObjectId("66f1c2a9e4b0a1b2c3d4e5f6"),
name: "Asha Rao",
email: "[email protected]",
age: 29,
address: { city: "Chennai", country: "India" },
skills: ["JavaScript", "MongoDB"],
createdAt: ISODate("2026-01-15T09:30:00Z")
} | Part | Meaning |
|---|---|
_id | Unique key (auto-generated if omitted) |
address | Embedded document — no separate table needed |
skills | Array stored inside the same record |
| BSON types | Dates, ObjectId, decimals beyond plain JSON |
Documents in one collection can differ, but real apps still follow a consistent shape. You can enforce one with schema validation. Max document size is 16 MB.
MongoDB vs SQL
If you know MySQL or PostgreSQL, map the ideas like this:
| SQL | MongoDB |
|---|---|
| Database | Database |
| Table | Collection |
| Row | Document |
| Column | Field |
| Primary key | _id |
| JOIN | Embed data, or use $lookup |
Same query, two styles
Users older than 25 — name and email, sorted by name:
SELECT name, email
FROM users
WHERE age > 25
ORDER BY name; db.users.find(
{ age: { $gt: 25 } },
{ name: 1, email: 1, _id: 0 }
).sort({ name: 1 }) In find(), the first argument is the filter (WHERE) and the second picks fields (SELECT).
When to choose which
| Prefer MongoDB when… | Prefer SQL when… |
|---|---|
| Data is naturally nested, like JSON | Data needs many joins across tables |
| The shape of records changes often | The schema is stable and strict |
| You need to scale across many servers | Your team and tools rely on SQL |
Your First MongoDB Commands
Insert one document and read it back in mongosh. MongoDB creates the database and collection on the first insert.
use school
db.students.insertOne({ name: "Ravi", grade: 8, subjects: ["Math", "Science"] })
db.students.find({ grade: 8 }) How It Works
1. Switch database. use school selects (or creates) the database.
2. Insert. insertOne adds one document to the students collection.
3. Query. find({ grade: 8 }) returns matching documents.
To run this yourself, follow the MongoDB installation guide. Updates and deletes are covered in CRUD operations.
Where Is MongoDB Used?
Common workloads where the document model fits well:
| Use case | Why MongoDB fits |
|---|---|
| Web & mobile backends | JSON APIs map cleanly to documents (MERN / MEAN stacks) |
| Product catalogs | Each product can have different attributes |
| Content platforms | Posts, tags, and comments nest in one document |
| User profiles | Preferences differ per user and change often |
| IoT & events | High write volume and flexible event shapes |
| Analytics dashboards | Aggregation pipelines summarize data in place |
What Should You Learn Next?
Follow this path. Each topic has its own tutorial page.
| Step | Topic | What you learn |
|---|---|---|
| 1 | Installation | Community Server, mongosh, or Atlas |
| 2 | CRUD Operations | Insert, find, update, delete |
| 3 | Operators | Filters like $gt and $in |
| 4 | Indexes | Faster queries on large collections |
| 5 | Data Modeling | Embed vs reference |
| 6 | Aggregation | Stages and accumulators |
| 7 | Replication | Replica sets and failover |
| 8 | Sharding | Scale across servers |
Key Takeaways
- MongoDB is a NoSQL document database built for flexible, JSON-like data.
- Hierarchy: database → collection → document → field.
- Storage: BSON documents can nest objects and arrays.
- Queries: use
find()and aggregation — not SQLSELECT.
One line: MongoDB stores JSON-like documents in collections — next, install it and practice CRUD in mongosh.
Frequently Asked Questions
Did you know?
MongoDB stores data as BSON documents in collections. Hierarchy: database → collection → document → field. Query with find(), not SQL.
Next: MongoDB Installation
Install Community Server and mongosh, or create a free Atlas cluster.
11 people found this page helpful
