KeplerGrid guide

Export MongoDB aggregation results to CSV or JSON

In the Aggregation tab, open Pipeline files and look under Export full result. Choose CSV for a spreadsheet or Extended JSON to retain MongoDB type information. KeplerGrid saves the results directly to a file, without creating a temporary collection.

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.

KeplerGrid Pipeline files shows Export full result with CSV and Extended JSON above the East and West results
Open Pipeline files and choose CSV or Extended JSON under Export full result. The sample returns one paid order in East and two in West.
"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.