What is MongoDB?
Where your data lives. MongoDB stores information as flexible, JSON-like documents — a natural fit for JavaScript apps.
What you will learn
- Explain what a database is and why apps need one
- Understand documents and collections
- Compare NoSQL to traditional SQL tables
Why a database?
Apps need to store data permanently — users, posts, orders. A database keeps that data safe even when the server restarts. In your Express API, the tasks array lost everything on restart; a database fixes that.
Documents and collections
MongoDB is a NoSQL database that stores data as documents — JSON-like objects. Documents live in collections. If you know JavaScript objects and arrays, you already understand MongoDB.
// A MongoDB document (looks just like a JS object)
{
"_id": "65f1a...",
"name": "Asha Rao",
"email": "asha@example.com",
"skills": ["HTML", "CSS", "React"],
"age": 22
}Read it like a JavaScript object. _id is a unique label MongoDB gives every document automatically. name and email hold text (strings), skills holds a list (an array), and age holds a number. So a “document” is just a bundle of named pieces of data — exactly like the objects you already write in JavaScript.
| MongoDB term | Is like a... | In JavaScript |
|---|---|---|
| Document | A single record | An object { } |
| Collection | A group of records | An array of objects [ ] |
| Database | The whole store | Your data folder |
| Field | A piece of data | An object property |
Note: Unlike SQL databases (rigid tables with fixed columns), MongoDB documents are flexible — different documents in a collection can have different fields. This suits fast-changing apps.
Tip: Every document gets a unique _id automatically. It is how you reference and find that exact document later.
Q. In MongoDB, a single record is called a:
✍️ Practice
- Write a MongoDB-style document describing yourself with at least four fields.
- List three things in a real app that would be stored in a database.
🏠 Homework
- Explain, in your own words, the difference between a document and a collection.