Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

MongoDB Aggregation Pipeline

12. 11. 2025 Updated: 28. 03. 2026 1 min read intermediate

Aggregation pipeline is MongoDB’s equivalent of SQL GROUP BY, JOIN and subqueries. Pipeline stages transform data step by step.

Basic Pipeline

db.orders.aggregate([ { $match: { status: “completed”, date: { $gte: ISODate(“2024-01-01”) } } }, { $group: { _id: “$customer_id”, totalSpent: { $sum: “$amount” }, orderCount: { $count: {} } }}, { $sort: { totalSpent: -1 } }, { $limit: 10 } ]);

$lookup (JOIN)

db.orders.aggregate([ { $lookup: { from: “customers”, localField: “customer_id”, foreignField: “_id”, as: “customer” }}, { $unwind: “$customer” }, { $project: { orderDate: 1, amount: 1, customerName: “$customer.name” }} ]);

Key Takeaway

$match first (uses indexes), $group for aggregations, $lookup for joins. Pipeline = SQL for MongoDB.

mongodbnosqldatabaseaggregation
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.