Examples
Six annotated MongoDB node configurations covering inserts, queries, atomic updates, aggregation analytics, full-text search, and inventory management.
Example 1: Store Workflow Execution Audit Record
Workflow position: Final node before Stop Workflow (or inside a Finally Block to guarantee execution).
{
"credential_id": "mongodb-atlas-prod",
"resource": "document",
"operation": "insert",
"database": "audit",
"collection": "workflow_executions",
"document": {
"workflow_id": "{{ workflow.id }}",
"workflow_name": "order-processing-v2",
"triggered_by": "{{ vars.trigger_source }}",
"operator_email": "{{ vars.operator_email }}",
"started_at": "{{ workflow.started_at }}",
"completed_at": "{{ now() }}",
"duration_ms": "{{ vars.duration_ms }}",
"input_order_id": "{{ vars.order_id }}",
"outcome_status": "{{ vars.final_status }}",
"outcome_message": "{{ vars.outcome_message }}",
"steps_executed": "{{ vars.steps_executed }}",
"environment": "{{ env.DEPLOY_ENV }}"
}
}
_id is available as $node.InsertAuditRecord.output.inserted_id and can be included in success notifications for traceability.Example 2: Query Customer Profile for Personalisation
Workflow position: Early in the workflow, after receiving the customer ID from a trigger or form input.
{
"credential_id": "mongodb-atlas-prod",
"resource": "document",
"operation": "find",
"database": "crm",
"collection": "customers",
"filter": {
"customer_id": "{{ vars.customer_id }}",
"status": "active"
},
"projection": {
"customer_id": 1,
"full_name": 1,
"email": 1,
"tier": 1,
"preferences": 1,
"last_purchase_date": 1,
"total_spend_ytd": 1,
"_id": 0
},
"limit": 1
}
$node.GetCustomer.output.count == 0 to handle unknown customers. The tier and preferences fields drive personalised content in the Email SMTP node.Example 3: Atomic Order Status Transition
Workflow position: Webhook Trigger → Validate Payment → MongoDB find-one-and-update → Route to fulfilment workflow.
{
"credential_id": "mongodb-atlas-prod",
"resource": "document",
"operation": "find-one-and-update",
"database": "ecommerce",
"collection": "orders",
"filter": {
"order_id": "{{ vars.order_id }}",
"status": "pending_payment"
},
"update": {
"$set": {
"status": "confirmed",
"payment_confirmed_at": "{{ now() }}",
"payment_reference": "{{ vars.payment_reference }}",
"updated_at": "{{ now() }}"
},
"$push": {
"status_history": {
"from_status": "pending_payment",
"to_status": "confirmed",
"changed_at": "{{ now() }}",
"trigger": "payment_webhook",
"payment_ref": "{{ vars.payment_reference }}"
}
}
},
"return_document": "after",
"upsert": false
}
$node.ConfirmOrder.output.found is false if the order was already confirmed (duplicate webhook) — use an If Condition to handle idempotently. The updated document drives the Sub-Workflow trigger for fulfilment.Example 4: Daily Revenue Aggregation for Reporting
Workflow position: Scheduled Trigger → Variable Assignment (set date range) → MongoDB aggregate → Insert summary → Email report.
{
"credential_id": "mongodb-atlas-prod",
"resource": "document",
"operation": "aggregate",
"database": "ecommerce",
"collection": "orders",
"pipeline": [
{
"$match": {
"status": "completed",
"completed_at": {
"$gte": "{{ vars.report_date_start }}",
"$lt": "{{ vars.report_date_end }}"
}
}
},
{ "$unwind": "$line_items" },
{
"$group": {
"_id": {
"category": "$line_items.category",
"region": "$shipping_region"
},
"revenue": { "$sum": "$line_items.subtotal" },
"units_sold": { "$sum": "$line_items.quantity" },
"order_count": { "$sum": 1 },
"avg_item_value": { "$avg": "$line_items.unit_price" }
}
},
{ "$sort": { "revenue": -1 } },
{
"$project": {
"_id": 0,
"category": "$_id.category",
"region": "$_id.region",
"revenue": 1,
"units_sold": 1,
"order_count": 1,
"avg_item_value": { "$round": ["$avg_item_value", 2] }
}
}
]
}
$node.DailyRevenueAgg.output.results contains the category-by-region breakdown array. A downstream insert node writes this array as a summary document to the daily_reports collection. The Email SMTP node formats the top 5 categories as an HTML table for the morning report.Example 5: Atlas Full-Text Product Search
Workflow position: HTTP Request Trigger → MongoDB aggregate (Atlas $search) → HTTP Response with results.
{
"credential_id": "mongodb-atlas-prod",
"resource": "document",
"operation": "aggregate",
"database": "catalogue",
"collection": "products",
"pipeline": [
{
"$search": {
"index": "product_search",
"compound": {
"must": [
{
"text": {
"query": "{{ vars.search_query }}",
"path": ["name", "description", "tags"],
"fuzzy": { "maxEdits": 1 }
}
}
],
"should": [
{
"text": {
"query": "{{ vars.search_query }}",
"path": "name",
"score": { "boost": { "value": 3 } }
}
}
],
"filter": [
{ "equals": { "path": "in_stock", "value": true } }
]
}
}
},
{
"$project": {
"product_id": 1,
"name": 1,
"price": 1,
"category": 1,
"thumbnail_url": 1,
"score": { "$meta": "searchScore" },
"_id": 0
}
},
{ "$sort": { "score": -1 } },
{ "$limit": 10 }
]
}
Example 6: Inventory Decrement with Low-Stock Alert
Workflow position: Inside a Loop node iterating over order line items.
// Step 1 — Decrement stock count atomically
{
"credential_id": "mongodb-atlas-prod",
"resource": "document",
"operation": "find-one-and-update",
"database": "inventory",
"collection": "stock_levels",
"filter": {
"sku": "{{ vars.current_sku }}",
"quantity_available": { "$gte": "{{ vars.ordered_quantity }}" }
},
"update": {
"$inc": { "quantity_available": "{{ vars.ordered_quantity * -1 }}" },
"$set": {
"last_decremented_at": "{{ now() }}",
"last_order_id": "{{ vars.order_id }}"
}
},
"return_document": "after",
"upsert": false
}
// Step 2 — Check threshold (If Condition node after Step 1):
// Condition: $node.DecrementStock.output.document.quantity_available <= $node.DecrementStock.output.document.reorder_threshold
// True branch: Sub-Workflow trigger → procurement notification
// Step 3 — Handle insufficient stock (false = filter found no document with enough stock)
// If $node.DecrementStock.output.found == false: Stop Workflow with status=failed, message="Insufficient stock for SKU {{ vars.current_sku }}"
found: false for clean error handling. When remaining stock falls to the reorder threshold, a Sub-Workflow triggers an automated purchase order creation workflow.