Tech Terms Explained Open in the app →

MongoDB

Databases · Beginner · 5 min read

What is it?

MongoDB is a document database that stores data as flexible JSON-like documents instead of rigid tables.

Explain like I'm 5

MongoDB is like a box of labeled folders where each folder can hold a different set of papers — you don't have to make every folder identical.

Why was it created?

It was built so developers could store data in the same shape their code already uses, and change that shape easily as the app evolves.

Where is it used?

  • Content and catalog storage
  • Real-time analytics
  • Mobile and IoT backends
  • Rapid prototyping

Why should developers care?

MongoDB is a popular choice for fast-moving products and is common in JavaScript and startup stacks you may join.

How does it work?

Data is stored as documents grouped into collections. Each document is a flexible set of fields, so different documents in the same collection can have different shapes.

Real-world example

A product catalog stores each item as a document; a book has 'author' and 'pages' while a shirt has 'size' and 'color', with no schema migration needed.

Common use cases

  • Flexible or evolving data models
  • Storing nested/hierarchical data
  • Catalogs and user profiles
  • High write throughput

Advantages

  • Flexible schema
  • Maps naturally to application objects
  • Scales horizontally with sharding
  • Fast to start building

Disadvantages

  • Weaker for complex multi-table joins
  • Easy to create inconsistent data without discipline
  • Less ideal for heavy transactional accounting

When should you use it?

When your data is document-shaped or its structure changes often.

When should you avoid it?

When you need rich relational joins and strict cross-record consistency.

Alternatives

PostgreSQL (with JSONB)DynamoDBCouchbaseFirestore

Related terms

PostgreSQLDynamoDBCassandra

Interview questions

Beginner

  • What is a document database?
  • How does MongoDB differ from a relational database?

Intermediate

  • What is sharding and why use it?
  • How do indexes work in MongoDB?

Senior

  • How would you model a many-to-many relationship?
  • When does embedding beat referencing?

Common misconceptions

  • "MongoDB has no schema" — it has a flexible schema, but you still design your data shape.
  • "NoSQL means no transactions" — MongoDB supports multi-document transactions.

Fun facts

  • The name comes from the word 'humongous'.
  • Documents are stored in a binary JSON format called BSON.

Timeline

  • 2009 — First released

Learning resources

Quick summary

MongoDB stores flexible JSON-like documents, making it easy to model evolving, object-shaped data.

Cheat sheet

  • Document database (JSON-like)
  • Flexible schema per document
  • Scales via sharding
  • Great for evolving data models

If you remember only one thing

MongoDB stores data in the same flexible shape your code uses.