Skip to the workspace
Pebellslearn by building
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.

mongodb / SQL vs NoSQL — and When MongoDB Fits

Explore each scene at your own pace.

01 · The rule

The rule

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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.