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.$group — groups by "$productIds" and aggregates customerIds.$project — returns only _id, productId, distinctCustomerCount.$group, customerIds collects distinct values — one output document per distinct "$productIds".Live output from running this query against the sample dataset.
| productId | distinctCustomerCount |
|---|---|
| 6a710150fb3d9d8ba951f422 | 2 |
| 6a710150fb3d9d8ba951f423 | 1 |
| 6a710150fb3d9d8ba951f421 | 1 |
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.