documentdb icon
Read icon
IonToCsv icon
If icon
SlackIncomingWebhook icon
Schedule icon

DocumentDB analytics report with Slack digest

Run a daily DocumentDB aggregation pipeline in Kestra, export the grouped result to CSV, and post a Slack digest with real per-status revenue figures.

Categories
Data

Turn raw DocumentDB orders into a daily, decision-ready summary without writing a line of glue code. This blueprint runs a MongoDB-style aggregation pipeline against a DocumentDB orders collection, stores the grouped result in Kestra internal storage, converts it to a CSV report, and posts a Slack digest with the actual per-status order counts and revenue. It is a read-only analytics pattern (no documents are modified) and the reporting window is derived from the scheduled date rather than now(), so backfills and missed-run replays always report the correct day. Keywords: DocumentDB aggregation pipeline, daily orders report, CSV export, Slack digest, scheduled analytics, backfill-safe reporting.

How it works

  1. The daily_report Schedule trigger (io.kestra.plugin.core.trigger.Schedule) fires every day at 07:00 UTC via cron 0 7 * * *.
  2. The aggregate_orders task (io.kestra.plugin.documentdb.Read) runs an aggregationPipeline that $matches the previous UTC calendar day, $groups by status, sums orders and revenue, and $sorts by revenue. The window is bound to {{ trigger.date ?? execution.startDate }} and the created_at filter uses the EJSON $date form so it compares against a real BSON date. With fetchType: STORE, the result is written to internal storage as Ion.
  3. The to_csv task (io.kestra.plugin.serdes.csv.IonToCsv) converts that Ion result into a downloadable CSV with header: true.
  4. The fetch_groups task re-reads the same aggregation with fetchType: FETCH so the digest can surface in-memory rows.
  5. The report task (io.kestra.plugin.core.flow.If) branches on {{ (outputs.fetch_groups.size ?? 0) > 0 }}: notify_digest posts a Slack Block Kit digest of each status with its order count and revenue plus a CSV link, while notify_empty posts a distinct no-orders message so a quiet day is never mistaken for a broken pipeline.
  6. An errors handler (alert_failure) posts a Slack alert if any step fails, and every remote call retries three times at a 10s interval.

What you get

  • A daily per-status breakdown of order counts and revenue, sorted by revenue.
  • A CSV report in internal storage, linked directly in the Slack message for download.
  • A clear signal for empty windows instead of silence.
  • Backfill-safe windows that follow the scheduled date, not wall-clock time.

Who it's for

  • Analytics and data engineers who need a recurring DocumentDB report without standing up a separate ETL job.
  • Operations and revenue teams who want a morning orders digest in Slack.
  • Platform teams consolidating ad-hoc database scripts into versioned, observable flows.

Why orchestrate this with Kestra

DocumentDB has no built-in scheduler, no retry semantics, and no way to fan a query result out to CSV and Slack. Kestra adds the event and schedule triggers, automatic retries on every remote call, full execution lineage across the read, transform, and notify steps, and a declarative YAML definition you can version and review. The branching If and errors handler give you the operational guardrails a raw query cannot.

Prerequisites

  • A reachable DocumentDB Data REST API endpoint with an orders collection containing status, amount, and a date-typed created_at field (indexing created_at keeps the window query fast).
  • A Slack incoming webhook pointed at the channel that should receive the digest.
  • Outbound network access from Kestra workers to DocumentDB and Slack.
  • Note: the window filter only works if created_at is stored as a BSON/EJSON date. If it is a string, migrate the field or change the $match to compare against an ISO string in your documents' format, since a type mismatch silently returns zero rows.

Secrets

  • DOCUMENTDB_HOST: base HTTPS endpoint of the DocumentDB Data REST API.
  • DOCUMENTDB_USERNAME: basic-auth username for the DocumentDB API.
  • DOCUMENTDB_PASSWORD: basic-auth password for the DocumentDB API.
  • SLACK_WEBHOOK: Slack incoming webhook URL used to post the digest and failure alerts.

Quick start

  1. Add the four secrets above to your Kestra instance.
  2. Point the database and collection variables at your orders data.
  3. Run the flow manually to validate the pipeline and Slack delivery.
  4. Rely on the 07:00 UTC schedule, and trigger a backfill from the Triggers tab to re-run any past day (the window follows the scheduled date).

How to extend

  • Swap the $group key from status to region, channel, or product for a different cut of the data.
  • Add a second IonToCsv or a Parquet/JSON serde and push the file to S3, GCS, or a data warehouse.
  • Replace or supplement the Slack step with email or Microsoft Teams notifications.
  • Change the cron to hourly or weekly, or add a flow-trigger so the report runs after an upstream ingestion completes.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.