Try it with four sample orders
Connect KeplerGrid to a development MongoDB instance. In a scratch database, use an orders collection containing these four documents.
[
{
"region": "West",
"status": "paid"
},
{
"region": "West",
"status": "paid"
},
{
"region": "East",
"status": "paid"
},
{
"region": "East",
"status": "pending"
}
]
Open the collection, choose Aggregation, and select JSON. Paste this pipeline and click Run pipeline. It counts paid orders by region and sorts the result by region name.
[
{ "$match": {
"status": "paid"
} },
{ "$group": {
"_id": "$region",
"orders": { "$sum": 1 }
} },
{ "$project": {
"_id": 0,
"region": "$_id",
"orders": 1
} },
{ "$sort": { "region": 1 } }
]
Save your results
Under Pipeline files → Export full result, choose CSV… and save paid-orders.csv. The file has a header and two data rows.
"orders","region"
"1","East"
"2","West"
Choose Extended JSON… to save the same results as a JSON array. The East order count appears as {"$numberInt":"1"}.
What the full result includes
KeplerGrid reruns the current pipeline when you export. It saves every document the pipeline returns, even when the screen shows only a preview. A $limit in the pipeline still applies. If the underlying data changes between preview and export, the exported values can change too.
Use a read-only pipeline. Stages such as $out and $merge write to a collection and are blocked in this export. You can explore aggregations in the built-in sample workspace. File export requires a MongoDB connection.
How to read a MongoDB aggregation Explain plan
Export a full MongoDB collection to JSON Lines when you need the source documents.
Download KeplerGrid or learn to debug a pipeline stage by stage.