Skip to content
Justice Tech School

One to Many Patterns

Few children: embed an array. Many children: reference the parent from each child. Huge sets: store a parent id on children and avoid unbounded arrays.

Example
// few
{ _id: 1, name: "Ada", phones: ["1", "2"] }
// many
db.comments.insertOne({ postId: 1, text: "Nice" })
db.comments.find({ postId: 1 })

Exercise

Parent reference.

{ Id: 1 }

Quiz Test

Why avoid unbounded arrays?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.