Run MongoDB aggregation pipelines when a plain find is not expressive enough and you need grouping, joins, reshaping, or materialized outputs.
Use this skill for reporting, enrichment, reshaping, and multi-stage query logic.
MONGODB_URIAGGREGATION_INPUT_JSON or stdin with database, collection, and pipelineexport AGGREGATION_INPUT_JSON='{"database":"app","collection":"orders","pipeline":[{"$match":{"status":"paid"}},{"$group":{"_id":"$customerId","revenue":{"$sum":"$total"}}},{"$sort":{"revenue":-1}}],"options":{"allowDiskUse":true}}'
node ./scripts/run-pipeline.js
$match and other narrowing stages as early as possible.$project tight so later stages do less work.explain mode if the pipeline is slow, then check [[mongodb/indexes]].$merge and $out as write operations that need extra review.allowDiskUse can keep a large pipeline running, but it does not fix poor stage ordering.