Documents, collections and modelling
MongoDB stores BSON documents; the schema is a design choice, not an accident.
What you will be able to do
- Design around access patterns, not around entity diagrams alone.
- Embed small, bounded, co-read values; reference large or shared collections.
- Enforce shape in application validation and schema validation.
In plain English
Embed data that is read and written together; reference data that grows independently. An unbounded array inside a document eventually hits a size limit and makes updates expensive.
db.courses.insertOne({
slug: "mongodb",
title: "MongoDB Foundations",
published: true,
modules: [
{ title: "Documents", lessons: 2 },
{ title: "Queries", lessons: 3 }
],
createdAt: new Date()
})Your turn
EasyModel a small course
Insert a course document with slug, title, published and a bounded modules array.
JAVASCRIPT · starter
db.courses.insertOne({})Check your understanding before moving on.
Knowledge checkQuestion 1
When is embedding a related array a good choice?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.