</>
Skip to content
MongoDB lessons (28/38)

MongoDB — Relationships

Relationship Types

TypeDescription
One-to-OneSingle related document
One-to-ManyMultiple related documents
Many-to-ManyMultiple on both sides

Embedding (One-to-One)

{
  name: "John",
  profile: {
    bio: "Developer",
    website: "example.com"
  }
}

Referencing (One-to-Many)

// User document
{ _id: ObjectId("..."), name: "John" }

// Order documents
{ userId: ObjectId("..."), total: 100 }

Population

db.orders.aggregate([
  {
    $lookup: {
      from: "users",
      localField: "userId",
      foreignField: "_id",
      as: "user"
    }
  }
])

Mini Practice

  1. Design one-to-one
  2. Design one-to-many
  3. Use $lookup for references
  4. Choose embedding vs referencing

Up Next

Continue with Transactions — multi-document transactions.

Related Topics

Frequently Asked Questions about Relationships

What is Relationships in MongoDB?

Relationships is a fundamental concept in MongoDB. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Relationships?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Relationships.

Why is Relationships important in MongoDB?

Relationships is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.