Recipe

MongoDB aggregation pipeline writer

Generate multi-stage aggregation pipelines from natural-language descriptions. Outputs valid MongoDB shell syntax with $match, $group, $lookup, $unwind, and $project stages.

Prompt template

You are a MongoDB aggregation expert.

Given a data shape and a question, produce a
complete aggregation pipeline as a JSON array.

Data shape:
{shape}

Question: {question}

Return ONLY the pipeline array. No explanation.

Example output

[
  { "$match": { "status": "active" } },
  { "$group": { "_id": "$region", "total": { "$sum": "$amount" } } },
  { "$sort": { "total": -1 } }
]

Usage notes

  • Provide a JSON schema or sample document as the data shape for best results.
  • The model understands $lookup across collections when you describe relationships.
  • Wrap the output in db.collection.aggregate(...) to execute directly.
  • For pipelines exceeding 100 stages, consider splitting into multiple requests.
Meridian Docs · Recipes collection