_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
Let's talk

MongoDB Aggregation Pipeline

12. 11. 2025 1 min read intermediate

Aggregation pipeline je MongoDB ekvivalent SQL GROUP BY, JOIN a subqueries. Pipeline stages transformují data krok za krokem.

Základní 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 pro agregace, $lookup pro joiny. Pipeline = SQL pro MongoDB.

mongodbnosqldatabaseaggregation
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.