MongoDB Tutorial 0/120 lessons ~6 min read Lesson 9
Understanding Collections
A collection is a group of documents — the MongoDB analogue of a SQL table, but without an enforced schema.
Course progress0%
Focus
5 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
A collection is a group of documents — the MongoDB analogue of a SQL table, but without an enforced schema. Collections live inside databases, and databases live inside the MongoDB cluster.
Understanding the topic
Collection essentials:
- Collections are created on first insert — no
CREATE TABLErequired. - Documents in a collection don't need identical schemas, but in practice you keep them similar.
- Use one collection per logical entity:
users,orders,products. - Each collection has its own indexes, validation rules, and storage stats.
- Capped collections, time-series collections and clustered collections are specialized variants.
Syntax reference
js
// Create implicitlydb.products.insertOne({ name: "Mug" });// Or explicitly with validationdb.createCollection("orders", {validator: {$jsonSchema: {required: ["userId", "total"],properties: {userId: { bsonType: "objectId" },total: { bsonType: "decimal", minimum: 0 }}}}});
Real-world use
A typical SaaS app might have collections for users, workspaces, projects, events, auditLogs, billing. Each is independently indexed and queried.
Best practices
- Name collections in lowercase, plural:
usersnotUser. - Add
$jsonSchemavalidators when the shape stabilizes. - Use time-series collections for IoT and metrics — they're 10× more space-efficient.
Ready to mark this lesson complete?Track your journey across the entire course.