Portal Community

When to Use

Configuration

Connection

FieldRequiredDescription
ConnectionUriRequiredMongoDB connection string. Reference via {{ $credentials.mongodbAtlas }}.
DatabaseRequiredTarget database name.
CollectionRequiredThe source collection for the first pipeline stage.

Operation

FieldRequiredDescription
PipelineRequiredArray of pipeline stage objects. Each element is a single-key object where the key is the stage operator (e.g. $match, $group). Minimum one stage required. BizFirst expressions are evaluated within stage values before execution. Example: [{"$match": {"tenantId": "{{ $json.tenantId }}"}}, {"$group": {"_id": "$status", "count": {"$sum": 1}}}].
AllowDiskUseOptionalDefault false. When true, MongoDB is permitted to spill intermediate results to disk if the in-memory sort or group buffer exceeds 100 MB. Enable for large aggregations involving many documents or complex multi-stage pipelines. Has a performance cost — enable only when needed.
Pipeline stage reference. All standard MongoDB aggregation stages are supported: $addFields, $bucket, $count, $facet, $geoNear, $graphLookup, $group, $limit, $lookup, $match, $merge, $out, $project, $redact, $replaceRoot, $sample, $search (Atlas), $set, $skip, $sort, $sortByCount, $unset, $unwind.

Sample Configuration

Weekly revenue summary by product category for a specific tenant and date range:

{
  "resource": "document",
  "operation": "aggregate",
  "ConnectionUri": "{{ $credentials.mongodbAtlas }}",
  "Database": "ecommerce",
  "Collection": "orders",
  "Pipeline": [
    {
      "$match": {
        "tenantId": "{{ $json.tenantId }}",
        "status": "completed",
        "completedAt": {
          "$gte": "{{ $json.weekStart }}",
          "$lt":  "{{ $json.weekEnd }}"
        }
      }
    },
    { "$unwind": "$lineItems" },
    {
      "$group": {
        "_id": "$lineItems.category",
        "totalRevenue": { "$sum": { "$multiply": ["$lineItems.qty", "$lineItems.unitPrice"] } },
        "orderCount":   { "$sum": 1 },
        "avgOrderValue":{ "$avg": "$total" }
      }
    },
    { "$sort": { "totalRevenue": -1 } },
    {
      "$project": {
        "_id": 0,
        "category":      "$_id",
        "totalRevenue":  { "$round": ["$totalRevenue", 2] },
        "orderCount":    1,
        "avgOrderValue": { "$round": ["$avgOrderValue", 2] }
      }
    }
  ],
  "AllowDiskUse": false
}

Validation Errors

ErrorCause
connectionUri is requiredConnectionUri is empty or not provided.
database is requiredDatabase field is empty.
collection is requiredCollection field is empty.
pipeline array cannot be emptyPipeline is null, an empty array [], or not an array. At least one stage is required.

Output — Success Port

FieldTypeDescription
countintegerNumber of documents in the pipeline result set. For $group operations this is the number of groups; for $match + $project it is the number of matching documents.
documentsarrayThe full result set as an array of objects. Each element represents one output document from the final pipeline stage. Empty array [] when the pipeline produces no results.
statusstringAlways "success".
resourcestringAlways "document".
operationstringAlways "aggregate".

Sample Output

{
  "count": 3,
  "documents": [
    {
      "category": "Footwear",
      "totalRevenue": 42180.50,
      "orderCount": 287,
      "avgOrderValue": 94.22
    },
    {
      "category": "Accessories",
      "totalRevenue": 18740.00,
      "orderCount": 412,
      "avgOrderValue": 45.48
    },
    {
      "category": "Apparel",
      "totalRevenue": 11230.75,
      "orderCount": 189,
      "avgOrderValue": 59.42
    }
  ],
  "status": "success",
  "resource": "document",
  "operation": "aggregate"
}

Expression Reference

ExpressionReturnsDescription
{{ $output.WeeklySummary.count }}integerNumber of result documents. Use in IfCondition to branch when the pipeline returns no data.
{{ $output.WeeklySummary.documents }}arrayFull results array. Pass to a Loop node to process each category row individually (e.g. send per-category alerts).
{{ $output.WeeklySummary.documents[0] }}objectFirst result document — e.g. the top revenue category after sorting.
{{ $output.WeeklySummary.documents[0].category }}stringThe category field from the top result.
{{ $output.WeeklySummary.documents[0].totalRevenue }}numberNumeric field from the aggregation output — use directly in calculations or report templates.
{{ $output.WeeklySummary.documents | length }}integerEquivalent to count — inline length computation.

Node Policies & GuardRails

PolicyRecommendation
Credential storageAlways reference ConnectionUri from BizFirst Credentials Manager. Never embed raw credentials in pipeline expressions.
Always $match firstPlace a $match stage as the first pipeline stage to leverage indexes and reduce the document set before expensive $group, $lookup, or $unwind stages. A pipeline that starts with $group on a large collection performs a full collection scan.
AllowDiskUse for large datasetsEnable AllowDiskUse: true for pipelines that sort or group more than 100 MB of intermediate data. Without it, MongoDB aborts the operation with an ExceededMemoryLimit error. Disk spillage is slower — also consider adding a $limit stage to reduce result size.
Index the $match fieldsAll fields used in the initial $match stage should have supporting indexes. Check index usage with explain() in MongoDB Compass or Atlas before deploying aggregations on production collections.
Multi-tenant $matchAlways include tenantId as the first condition in the $match stage to scope aggregations to the correct tenant's data in shared collections.
Limit result setAdd a $limit stage at the end of exploration pipelines. Aggregations that return thousands of documents consume significant memory in the workflow execution context. Project only the fields needed for downstream steps.
$lookup performanceEnsure the localField and foreignField in $lookup stages are indexed on both collections. Unindexed lookups perform nested loop scans and become exponentially slow as collection size grows.
Atlas $search stageThe $search stage is available only on MongoDB Atlas M10+ clusters. It requires an Atlas Search index on the collection. Verify cluster tier and index existence with searchindex/list before using this stage in production.

Workflow Examples

Example 1 — Order-Product Join with $lookup

{
  "resource": "document",
  "operation": "aggregate",
  "ConnectionUri": "{{ $credentials.mongodbAtlas }}",
  "Database": "ecommerce",
  "Collection": "orders",
  "Pipeline": [
    { "$match": { "customerId": "{{ $json.customerId }}", "tenantId": "{{ $json.tenantId }}" } },
    { "$unwind": "$lineItems" },
    {
      "$lookup": {
        "from": "products",
        "localField": "lineItems.sku",
        "foreignField": "sku",
        "as": "productDetail"
      }
    },
    { "$unwind": "$productDetail" },
    {
      "$project": {
        "_id": 0,
        "orderId": 1,
        "sku": "$lineItems.sku",
        "productName": "$productDetail.name",
        "qty": "$lineItems.qty",
        "unitPrice": "$lineItems.unitPrice",
        "lineTotal": { "$multiply": ["$lineItems.qty", "$lineItems.unitPrice"] }
      }
    },
    { "$sort": { "orderId": -1 } },
    { "$limit": 100 }
  ],
  "AllowDiskUse": false
}

Example 2 — Atlas Full-Text Search on Support Tickets

{
  "resource": "document",
  "operation": "aggregate",
  "ConnectionUri": "{{ $credentials.mongodbAtlas }}",
  "Database": "support",
  "Collection": "tickets",
  "Pipeline": [
    {
      "$search": {
        "index": "ticket_search_index",
        "text": {
          "query": "{{ $json.searchQuery }}",
          "path": ["title", "description", "resolution"]
        }
      }
    },
    { "$match": { "tenantId": "{{ $json.tenantId }}", "status": { "$ne": "deleted" } } },
    { "$limit": 20 },
    {
      "$project": {
        "_id": 0,
        "ticketId": 1,
        "title": 1,
        "status": 1,
        "priority": 1,
        "score": { "$meta": "searchScore" }
      }
    }
  ],
  "AllowDiskUse": false
}

Example 3 — Monthly Revenue by Tenant KPI Report

{
  "resource": "document",
  "operation": "aggregate",
  "ConnectionUri": "{{ $credentials.mongodbAtlas }}",
  "Database": "billing",
  "Collection": "invoices",
  "Pipeline": [
    {
      "$match": {
        "status": "paid",
        "paidAt": {
          "$gte": "{{ $json.monthStart }}",
          "$lt":  "{{ $json.monthEnd }}"
        }
      }
    },
    {
      "$group": {
        "_id": "$tenantId",
        "totalRevenue": { "$sum": "$amount" },
        "invoiceCount": { "$sum": 1 },
        "avgInvoiceValue": { "$avg": "$amount" }
      }
    },
    { "$sort": { "totalRevenue": -1 } },
    {
      "$project": {
        "_id": 0,
        "tenantId": "$_id",
        "totalRevenue": { "$round": ["$totalRevenue", 2] },
        "invoiceCount": 1,
        "avgInvoiceValue": { "$round": ["$avgInvoiceValue", 2] }
      }
    }
  ],
  "AllowDiskUse": true
}