MongoDB Foundations·Documents with discipline

Documents, collections and modelling

MongoDB stores BSON documents; the schema is a design choice, not an accident.

Beginner 13 min read Lesson 6 of 300 Challenge included
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.

mongoshJavaScript
db.courses.insertOne({
  slug: "mongodb",
  title: "MongoDB Foundations",
  published: true,
  modules: [
    { title: "Documents", lessons: 2 },
    { title: "Queries", lessons: 3 }
  ],
  createdAt: new Date()
})
Your turn

Model a small course

Easy

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 in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 6 of 300 · 0% of course