Export a collection to CSV or Excel
Get a result or a whole collection out of MongoDB, with the BSON types intact and without loading the file into memory.
Two different things are called export, and picking the wrong one is the usual mistake.
- Export the result you are looking at, from the result toolbar. It exports what the query returned.
- Export the collection, from the collection’s context menu in the sidebar. It exports every matching document, not only the page you loaded.
Export what you are looking at
- Run the query.
- Press Export above the result.
- Choose the format.
You are asked whether to export the loaded results or every document the query matches. The second option re-runs the query as a stream, so a 2 million document export does not have to fit in memory.
Choose the right format
| Format | Use it for | Watch out for |
|---|---|---|
| Extended JSON, canonical | Anything going back into MongoDB | Verbose. Collection export only |
| Extended JSON, relaxed | Reading, and most tooling | Lossy for 64-bit integers, by specification |
| NDJSON | Streaming into another tool | One document per line, no enclosing array |
| CSV | A spreadsheet, or a colleague | Values are written as text, dates as ISO strings |
| Excel, Pro | A colleague who will not open a CSV | Same as CSV: no BSON typing |
Where the canonical choice lives matters. EJSON Mode, with canonical beside relaxed, is
offered in one place only: the collection export dialog’s advanced JSON options. Database
export and both result-export scopes have no such choice and always write relaxed.
And the loaded-results JSON export is not Extended JSON at all. It strips every type wrapper: a 64-bit integer or a decimal is written as a JSON string, a binary as base64 text, and a timestamp or regular expression as a readable label. It is a readable export, not a re-importable one.
So: if the data has to come back exactly, export the collection and choose Canonical. Relaxed exists for readability, and it is already wrong for a 64-bit integer above 9,007,199,254,740,992 before the file leaves your machine. Extended JSON and BSON has the full story.
Options worth knowing
- Custom delimiter for CSV, so a semicolon locale opens cleanly.
- Array flattening for CSV, which turns
items[0].skuinto its own column. - gzip on both JSON and CSV, applied as it streams.
- Formatting on JSON, if a human is going to read it.
Export a whole database
Right-click the database and choose export. It writes one file per collection into a directory and reports the file count before it starts. This is Pro.