MongoDB BasicsCore· 30 min read

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 document — JSON-like data
// 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 termIs like a...In JavaScript
DocumentA single recordAn object { }
CollectionA group of recordsAn array of objects [ ]
DatabaseThe whole storeYour data folder
FieldA piece of dataAn 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:

Answer: MongoDB stores data as documents (JSON-like objects) grouped into collections. Rows/tables/columns are SQL terms.

✍️ Practice

  1. Write a MongoDB-style document describing yourself with at least four fields.
  2. List three things in a real app that would be stored in a database.

🏠 Homework

  1. Explain, in your own words, the difference between a document and a collection.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →