MongoDB query compiled from plain English against the ecommerce sample schema, then verified by running it.
{
"type": "aggregation",
"collection": "orders",
"pipeline": [
{},
{},
{},
{},
{},
{},
{},
{},
{}
]
}
$unwind — flattens $productIds into one document per element.$lookup — joins the products collection on productIds → _id.$unwind — flattens $product into one document per element.$group — groups by "$customerId" and aggregates totalSpent, orderCount.$project — returns only averageOrderValueCents.$match — filters on averageOrderValueCents.$lookup — joins the customers collection on _id → _id.$unwind — flattens $customer into one document per element.$project — returns only _id, name, email, status, createdAt, averageOrderValueCents.totalCents stores money as an integer number of cents — divide by 100 before displaying it.$group, totalSpent totals $totalCents, orderCount counts documents in each group — one output document per distinct "$customerId".Live output from running this query against the sample dataset.
| averageOrderValueCents | name | status | createdAt | |
|---|---|---|---|---|
| 10300 | Marcus Reid | marcus@example.com | active | 2026-05-15T20:08:22.972Z |
| 32900 | Priya Nair | priya@example.com | inactive | 2026-01-15T20:08:22.972Z |
| 14400 | Ava Chen | ava@example.com | active | 2026-04-05T20:08:22.972Z |
Write this in plain English instead. Mask Databases compiles the sentence above into exactly this query at build time — no AI at runtime, and you can read the output in a diff.
Try it in the playground → No signup, runs in your browser.