Collections vs SQL Tables
Learners will contrast MongoDB collections with relational tables and appreciate how a flexible schema changes data design.
Tables vs Collections at a Glance
SQL's basic unit is the table, where every row has identical columns. MongoDB's is the collection — a group of documents that can each differ.
Fixed Schema: The SQL Way
SQL needs a fixed schema defined before any data goes in, and changing it later can rebuild the whole table. Rigid, but predictable and storage-efficient.
-- SQL table: schema defined upfront, rigid
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(200) UNIQUE NOT NULL,
age INT,
created_at TIMESTAMP DEFAULT NOW()
);
-- Every row must have exactly these columnsAll lessons in this course
- What Is a BSON Document?
- Collections vs SQL Tables
- Databases, Collections, and Namespaces
- The mongosh Shell Essentials