querydrill

Learn › Aggregation

The aggregation pipeline

Stages, order, and reshaping documents with $match and $project.

By the end: Read a pipeline top to bottom and predict the shape at every stage.

Lessons

6
  1. find() vs aggregate()

    find() vs aggregate() in MongoDB: what find can and cannot do, and the point at which you need a pipeline.

  2. What a pipeline actually is

    A MongoDB aggregation pipeline is an ordered list of stages, each transforming the documents the previous stage produced.

  3. $match, and why it goes first

    MongoDB $match filters documents inside an aggregation pipeline, using the same operators as find(). Put it first.

  4. $project and computed fields

    MongoDB $project reshapes documents: include and exclude fields, rename them, and build new computed fields.

  5. $set and $addFields

    MongoDB $set and $addFields add computed fields while keeping everything else. The same stage under two names.

  6. $sort, $limit, $skip — order matters

    MongoDB $sort, $limit and $skip as pipeline stages, and why swapping their order changes the answer, not just the speed.

Drills

1 easy · 1 medium
Start reading →Skip to the drills