Mongo Aggregation

The Mongo Aggregation Component allows users to filter, group, sort, and transform data from one or more MongoDB collections using the MongoDB Aggregation Framework.

Aggregation pipelines consist of multiple stages that sequentially process data, making it possible to implement complex transformations such as grouping, projecting fields, calculating aggregates, and reshaping datasets before passing them to downstream pipeline components.

Key Capabilities

  • Run MongoDB aggregation pipelines directly in pipeline workflows.

  • Support for multiple connection types: Standard, SRV, and Connection String.

  • Configure SSL connections with uploaded certificates.

  • Write custom aggregation scripts to filter, group, project, and transform MongoDB collections.

Configuration Overview

All Mongo Aggregation configurations are grouped into the following sections:

  • Basic Information

  • Meta Information

  • Resource Configuration

  • Connection Validation

Configuring Meta Information

Connection Type

Select the MongoDB connection type:

  • Standard – Requires host IP address and port.

  • SRV – Uses DNS SRV connection; no port required.

  • Connection String – Enter full MongoDB URI connection string.

Database Connection

  • Host IP Address (*) – Provide the IP address of the MongoDB host.

  • Port (*) – Enter the MongoDB port number (only for Standard type).

  • Username (*) – Database username.

  • Password (*) – Database password.

  • Database Name (*) – The database to query.

  • Collection Name (*) – The MongoDB collection to read from.

  • Additional Parameters – (Optional) Key-value pairs for extra connection properties.

SSL Configuration

  • Enable SSL – Check this option to use SSL-secured connections.

  • Certificate Folder – If SSL is enabled, select the folder containing SSL certificates uploaded in Admin Settings.

Aggregation Script

  • Script – Enter the MongoDB aggregation query pipeline script.

    • Define stages such as $match, $group, $project, $sort, $lookup, etc.

    • Multiple stages can be combined in an array.

Example Aggregation Script

[
  { 
    "$match": { "status": "active" } 
  },
  { 
    "$group": { 
      "_id": "$region", 
      "totalUsers": { "$sum": 1 }, 
      "avgAge": { "$avg": "$age" } 
    } 
  },
  { 
    "$sort": { "totalUsers": -1 } 
  }
]

This example:

  • Filters documents where status = active.

  • Groups users by region.

  • Calculates total users and average age per region.

  • Sorts results by totalUsers in descending order.

Example Use Cases

  • Aggregate customer records by location and calculate counts.

  • Transform raw IoT sensor data into grouped metrics per device.

  • Join and project multiple fields to create enriched analytical views.

  • Filter transaction logs and summarize revenue by category.