1. What exactly is MongoDB? (The Big Picture First)
Imagine you are running an online book store (like Amazon but small scale).
In traditional SQL databases (MySQL, PostgreSQL):
- You need to decide every column before storing data → title, author, price, pages, isbn, publish_year, etc.
- Every book must have all these fields (or NULL).
- If tomorrow you want to add “audio_length_minutes” for audiobooks → you have to ALTER TABLE (painful for large tables).
- You store data in very strict rows & columns (like Excel sheet with fixed structure).
MongoDB says: “Relax yaar!”
- It is a NoSQL document database.
- Data is stored as flexible JSON-like documents.
- No fixed schema → different documents in same collection can have different fields.
- Perfect for modern apps: mobile apps, e-commerce, IoT, content management, real-time analytics, etc.
Official definition (2026 style):
MongoDB is a source-available, cross-platform, document-oriented NoSQL database that uses JSON-like BSON documents with optional schemas.
2. Key Concepts – Analogy Time
Think of a school:
| SQL (MySQL) | MongoDB | School Analogy |
|---|---|---|
| Database | Database | One entire school |
| Table | Collection | One class (e.g., 10th A) |
| Row / Record | Document | One student file |
| Column / Field | Field | One detail (name, marks, hobby, blood group) |
| Schema | Schema-less / Flexible | Some students have medical notes, some don’t |
Example student document in MongoDB:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "_id": "STU2025001", // auto-generated or you can set "name": "Rahul Sharma", "age": 16, "class": "10th A", "marks": { "math": 92, "science": 88, "english": 79 }, "hobbies": ["cricket", "coding", "guitar"], "isMonitor": true, "address": { "city": "Hyderabad", "pin": 500081 }, "lastExamDate": "2026-02-10" } |
Next student in same collection:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ "_id": "STU2025002", "name": "Priya Patel", "age": 15, "class": "10th A", "hobbies": ["dance"], "favoriteSubject": "Biology" // ← extra field, no problem! } |
See? No stress about missing fields or adding new ones.
3. Let’s Start Practically – Installation Options (2026)
Three popular ways beginners use today:
Option A – Easiest (Recommended for learning) Use MongoDB Atlas (cloud – free forever for small projects)
- Go to → https://www.mongodb.com/cloud/atlas
- Sign up (Google/GitHub/email)
- Create free cluster (M0 free tier – enough for learning)
- Create database user
- Get connection string (looks like: mongodb+srv://username:password@cluster0.abcde.mongodb.net/myFirstDatabase?retryWrites=true&w=majority)
Option B – Local (good for offline practice)
- Download MongoDB Community Server: https://www.mongodb.com/try/download/community
- Or use Docker (very popular in 2026):
|
0 1 2 3 4 5 6 |
docker run -d -p 27017:27017 --name mymongo -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=secret mongo:latest |
Option C – MongoDB Shell / mongosh (command line tool)
Comes with installation or install separately.
4. CRUD Operations – The Heart of MongoDB (Hands-on)
Open mongosh (new name of mongo shell) or use MongoDB Compass (GUI – very beginner friendly).
Let’s create our school database.
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// 1. Switch / create database (MongoDB creates it automatically when you use it) use school // 2. Create / Insert documents (CREATE) db.students.insertOne({ name: "Rahul Sharma", age: 16, city: "Hyderabad", marks: { math: 92, science: 88 }, active: true }) db.students.insertMany([ { name: "Priya Patel", age: 15, city: "Secunderabad", marks: { math: 95 }, hobby: "Dance" }, { name: "Amit Verma", age: 17, city: "Hyderabad", marks: { math: 65, physics: 72 }, sports: "Kabaddi" } ]) |
See output → it gives you insertedId or insertedIds.
|
0 1 2 3 4 5 6 7 8 9 10 11 |
// 3. Read documents (READ) db.students.find() // all students db.students.find({ city: "Hyderabad" }) // filter db.students.find({ "marks.math": { $gte: 90 } }) // math >= 90 db.students.find().pretty() // nice formatting db.students.findOne({ name: "Rahul Sharma" }) // only first match |
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// 4. Update (UPDATE) db.students.updateOne( { name: "Amit Verma" }, // filter { $set: { age: 18, "marks.math": 82 } } // what to change ) db.students.updateMany( { city: "Hyderabad" }, { $inc: { age: 1 } } // increment age by 1 for all Hyderabad students ) |
|
0 1 2 3 4 5 6 7 8 9 |
// 5. Delete (DELETE) db.students.deleteOne({ name: "Priya Patel" }) db.students.deleteMany({ age: { $lt: 16 } }) // delete all below 16 |
5. Most Important Query Operators (You will use these daily)
| Operator | Meaning | Example |
|---|---|---|
| $eq | equal | { age: { $eq: 16 } } |
| $gt / $gte | greater / greater or equal | { “marks.math”: { $gt: 85 } } |
| $in | value in array | { city: { $in: [“Hyderabad”, “Bangalore”] } } |
| $and / $or | logical | { $and: [ {age: {$gt:15}}, {city:”Hyderabad”} ] } |
| $exists | field exists | { hobby: { $exists: true } } |
6. Quick Mini Project – Let’s Build Something Useful
Imagine we’re making a movie review app.
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
use movieApp db.movies.insertMany([ { title: "RRR", year: 2022, genres: ["Action", "Drama"], rating: 8.1, cast: ["NTR", "Ram Charan"], language: "Telugu" }, { title: "Kalki 2898 AD", year: 2024, genres: ["Sci-Fi", "Action"], rating: 8.0, cast: ["Prabhas"], budget: "600 Cr" }, { title: "Pushpa 2", year: 2025, genres: ["Action", "Thriller"], rating: 8.5 } ]) // Find all Telugu action movies with rating > 8 db.movies.find({ $and: [ { genres: "Action" }, { language: "Telugu" }, { rating: { $gt: 8 } } ] }).pretty() |
Quick Summary Table – What You Learned Today
| Task | Command Example |
|---|---|
| Use/Create DB | use mydb |
| Insert one | db.collection.insertOne({…}) |
| Insert many | db.collection.insertMany([{}, {}]) |
| Find all | db.collection.find() |
| Find with condition | db.collection.find({ age: { $gt: 18 } }) |
| Update | db.collection.updateOne(filter, { $set: {..} }) |
| Delete | db.collection.deleteMany({ city: “Delhi” }) |
Want to go deeper next? Tell me:
- Want to learn Aggregation Pipeline (very powerful – like GROUP BY + more)?
- Indexing for fast search?
- How to connect MongoDB with Node.js / Python / Java?
- Atlas search / Vector search (very hot in 2026 for AI apps)?
Just say the word — we’ll continue the class! 🚀
Any doubts so far? Ask anything — no question is silly. 😄
