Skip to main content

๐Ÿ“Š Aggregations

Need powerful data crunching? Cascade lets you use MongoDB's aggregation pipelines right from your modelsโ€”no sweat! ๐Ÿงฎ

๐Ÿš€ What's Aggregation?โ€‹

Aggregation lets you process data records and return computed resultsโ€”think sums, averages, grouping, and more!

๐Ÿ—๏ธ How to Use Aggregationโ€‹

Just call the aggregate method on your model:

src/app.ts
const results = await Order.aggregate([
{ $match: { status: "completed" } },
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } },
]);

๐Ÿงฉ Common Use Casesโ€‹

  • Sum: Total up values
  • Average: Find the mean
  • Group: Organize by fields
  • Match: Filter your data
  • Project: Shape your output

๐Ÿง™โ€โ™‚๏ธ Pro Tip: Use with Modelsโ€‹

You can use aggregation for advanced reporting, analytics, and dashboardsโ€”all with your familiar model classes!

โš ๏ธ Best Practicesโ€‹

  • Use aggregation for heavy data processing, not simple queries.
  • Keep pipelines as short as possible for best performance.
info

Aggregation is super powerfulโ€”combine it with Cascade's models for next-level data magic!


๐ŸŒŸ What's Next?โ€‹