MongoDB Introduction

Beginner
6 min read
Updated: Oct 2026
NoSQL tutorial

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.

Remember
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.”

NeedHow MongoDB helps
Flexible dataDocuments in one collection do not need the same fields
Nested objectsRelated data can live in one document instead of many joined tables
Horizontal scaleSharding spreads data across servers
Fast iterationSchema can evolve without heavy migrations for every change

How MongoDB Organizes Data

Each level contains many of the next. Keep this hierarchy in mind.

LevelWhat it isExample
DatabaseContainer for related collectionsshop
CollectionGroup of similar documentsusers, orders
DocumentOne record (field–value pairs)One user profile
FieldA key inside a documentemail, age
_idUnique ID for every documentAuto-generated ObjectId

Cheat sheet — tools

ToolRole
mongodDatabase server process
mongoshInteractive shell used in this tutorial
DriversConnect apps (Node.js, Python, Java, …)
CompassDesktop GUI for browsing data
AtlasManaged MongoDB in the cloud

What Does a Document Look Like?

One document from a users collection:

document
{
  _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")
}
PartMeaning
_idUnique key (auto-generated if omitted)
addressEmbedded document — no separate table needed
skillsArray stored inside the same record
BSON typesDates, 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:

SQLMongoDB
DatabaseDatabase
TableCollection
RowDocument
ColumnField
Primary key_id
JOINEmbed data, or use $lookup

Same query, two styles

Users older than 25 — name and email, sorted by name:

SQL
SELECT name, email
FROM users
WHERE age > 25
ORDER BY name;
mongosh
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 JSONData needs many joins across tables
The shape of records changes oftenThe schema is stable and strict
You need to scale across many serversYour 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.

mongosh
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 caseWhy MongoDB fits
Web & mobile backendsJSON APIs map cleanly to documents (MERN / MEAN stacks)
Product catalogsEach product can have different attributes
Content platformsPosts, tags, and comments nest in one document
User profilesPreferences differ per user and change often
IoT & eventsHigh write volume and flexible event shapes
Analytics dashboardsAggregation pipelines summarize data in place

What Should You Learn Next?

Follow this path. Each topic has its own tutorial page.

StepTopicWhat you learn
1InstallationCommunity Server, mongosh, or Atlas
2CRUD OperationsInsert, find, update, delete
3OperatorsFilters like $gt and $in
4IndexesFaster queries on large collections
5Data ModelingEmbed vs reference
6AggregationStages and accumulators
7ReplicationReplica sets and failover
8ShardingScale 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 SQL SELECT.

One line: MongoDB stores JSON-like documents in collections — next, install it and practice CRUD in mongosh.

Frequently Asked Questions

Web and mobile backends, product catalogs, content apps, user profiles, IoT and event data, and analytics. It fits best when your data looks like JSON and changes over time.
MongoDB is a NoSQL document database. It stores records as JSON-like documents in collections and you query with methods such as find() instead of SQL.
Yes for learning and many production uses. Community Server is free to run; MongoDB Atlas has a free tier. Paid plans add support and larger clusters.
Yes. Use $lookup for joins between collections. Multi-document ACID transactions have been available since MongoDB 4.0. Good document design often embeds related data so joins are needed less often.
Both help. SQL is still the most common database skill. MongoDB is quicker to start if you already work with JavaScript or JSON APIs. Many teams use both.
Install MongoDB or create a free Atlas cluster, practice CRUD in mongosh, then learn operators, indexes, data modeling, aggregation, replication, and sharding.

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.

Installation guide →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful