Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/MongoDB
MongoDBmedium

Aggregation pipeline — what is it and what is it used for?

Tags
#aggregation#pipeline#group
Back to categoryPractice quiz

Answer

It’s a sequence of stages (`$match`, `$group`, `$project`, ...) that transforms documents and can compute aggregates. Use it for reporting, grouping, filtering, and shaping data on the server side.

db.orders.aggregate([
  { $match: { status: "PAID" } },
  { $group: { _id: "$customerId", total: { $sum: "$amount" } } }
])

Related questions

MongoDB
`$lookup`: what does it do and what is a common pitfall?
#mongo#lookup#aggregation
MongoDB
Aggregation pipeline performance: why put `$match` (and `$project`) early?
#mongo#aggregation#pipeline
MongoDB
What does `$lookup` do in MongoDB aggregation (and what’s a caveat)?
#lookup#aggregation#joins
MongoDB
How does the MongoDB aggregation pipeline work?
#aggregation#pipeline#mongodb