Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
MongoDB Basics  ›  Lesson

SQL vs NoSQL — and When MongoDB Fits

SQL vs NoSQL 12 minRelational databases split data into tables joined at read time, while document databases like MongoDB keep data that is read together in one document, which suits evolving, nested data read as a unit.

SQL vs NoSQL — and When MongoDB Fits

Your bookshop app shows a book page 10,000 times a day. In a relational database, that page might join a books table, a genres table, a book_genres link table and a publishers table on every view. A document database asks a different question: why not keep the page's data together from the start?

The rule

Tables split data and join on read; documents keep together what is read together.

SQL (relational) databases such as PostgreSQL and MySQL store data in tables with a fixed set of columns. Each fact is stored once, and queries join tables back together. They shine when data is highly interlinked and asked about in many different ways.

NoSQL is an umbrella term for databases that are not table-based. It covers document stores (MongoDB), key-value stores, wide-column stores and graph databases. MongoDB is a document store.

Relational MongoDB
Unit of data row in a table document in a collection
Shape fixed columns, changed with ALTER TABLE flexible, can vary per document
Related data separate tables plus joins embedded, or referenced by id
Query language SQL query documents and methods
Growing bigger usually a bigger server built-in sharding across servers

Two myths to drop: MongoDB is not schema-less chaos (you can enforce a schema with validation rules), and it does support multi-document ACID transactions. The difference is what the design leans on by default.

The shortcut

Ask "What does my app read together?" Then check the fit.

Should the bookshop use MongoDB?Step 1 of 4
  1. Find the reads

    The busiest screen is the book page: one book with its genres, publisher and ratings.

MongoDB tends to fit: content and catalogues, user profiles, event logs, IoT readings, and apps whose data shape keeps evolving. It fits less well when nearly every operation must update many separate, heavily linked records at once.

Drills

Answer fast — trust the rule.

quick drill

Which kind of database is MongoDB?

quick drill

A relational database typically answers "show this book with its genres" by…

quick drill

Which statement about MongoDB is true?

quick drill

Which project is the weakest natural fit for MongoDB?

Remember

  • Tables split data and join on read; documents keep together what is read together.
  • Shortcut: ask what the app reads together, whether shapes vary, and how tangled the links are.
  • Trap: MongoDB is not structure-free and not transaction-free.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainChoosing a database

Two projects: a product catalogue where each item type has different attributes and pages show one product at a time, and a bank ledger where every transfer touches several accounts that many reports join together. Explain which one fits MongoDB naturally and which one leans relational, and why.