Skip to content
Learn Netverks

Lesson

Step 24/36 67% through track

aggregation-intro

Aggregation introduction

Last reviewed Jun 1, 2026 Content v20260601
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
intermediate

This lesson

An orientation to the MongoDB track—documents, queries, and when document stores beat relational tables.

You need a clear map of the MongoDB track so documents, aggregation pipelines, and schema flexibility do not feel like magic.

You will apply Aggregation introduction in contexts like: In-app dashboards, funnel metrics, and ETL-lite without exporting every row to a warehouse.

Copy JavaScript shell queries from each lesson into mongosh or MongoDB Atlas Data Explorer—inspect matched documents and explain plans. The in-browser lab (execution_profile: none) ships later; mongosh is the practice path now. Also read the interview prep blocks; put $match as early as possible in the pipeline.

After you understand JSON and SQL trade-offs—when document flexibility outweighs relational joins.

The aggregation pipeline processes documents through stages—like a composable ETL inside the database.

First pipeline

db.orders.aggregate([
  { $match: { status: 'shipped' } },
  { $group: { _id: '$customerId', totalSpent: { $sum: '$total' } } },
  { $sort: { totalSpent: -1 } },
  { $limit: 10 }
])

Practice: Run aggregation pipelines in mongosh.

Stage order matters

Put $match early to reduce documents—indexes can help $match like find().

Important interview questions and answers

  1. Q: aggregate vs find?
    A: aggregate for transforms, grouping, joins; find for simple filters.
  2. Q: $group _id?
    A: Defines grouping key—null groups everything into one bucket.

Self-check

  1. Name first two stages in example.
  2. Why $match early?

Tip: Put $match first to shrink working set before $group.

Interview prep

Pipeline?
Ordered stages transforming documents.
$match early?
Reduces documents before expensive stages.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • $match first?
  • $group _id?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump