Skip to main content

Mongo Aggregation Builder

v1.0.0

Visual aggregation pipeline builder — $match, $group, $project, $lookup with preview.

MongoDB Aggregation Pipeline
db.orders.aggregate([
  // Stage 1: Filter
  { $match: { status: "completed" } },

  // Stage 2: Group and aggregate
  {
    $group: {
      _id: "$customerId",
      total: { $sum: "$amount" },
      count: { $sum: 1 },
    },
  },

  // Stage 3: Sort
  { $sort: { total: -1 } },

  // Stage 4: Limit
  { $limit: 20 },

  // Stage 5: Reshape output
  {
    $project: {
      _id: 0,
      customerId: "$_id",
      total: 1,
      count: 1,
    },
  },
]);

// Explain performance:
db.orders.aggregate([...]).explain("executionStats")