MongoDB query compiled from plain English against the ecommerce sample schema, then verified by running it.
{
"type": "aggregation",
"collection": "orders",
"pipeline": [
{},
{},
{},
{}
]
}
$lookup — joins the customers collection on customerId → _id.$unwind — flattens $customer into one document per element.$group — groups by "$customer._id" and aggregates customerName, firstOrderDate, mostRecentOrderDate.$project — returns only _id, customerName, firstOrderDate, mostRecentOrderDate.$group, customerName takes the first value in the group, firstOrderDate takes the lowest $placedAt, mostRecentOrderDate takes the highest $placedAt — one output document per distinct "$customer._id".Live output from running this query against the sample dataset.
| customerName | firstOrderDate | mostRecentOrderDate |
|---|---|---|
| Ava Chen | 2026-07-28T20:08:22.972Z | 2026-08-01T20:08:22.972Z |
| Sam Okafor | 2026-08-02T20:08:22.972Z | 2026-08-02T20:08:22.972Z |
| Priya Nair | 2026-07-19T20:08:22.972Z | 2026-07-19T20: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.