Skip to content
Monghoul

Import a JSON or CSV file

Load a file into a collection, choose a write strategy, and avoid the type inference traps that quietly corrupt data.

Checked against v1.11.0 Updated
The import dialog with a file chosen, its format detected, and the write strategy options
Import · Format detected from the file, and a write strategy to choose

Choosing the file sets the format from its extension, suggests a collection name, and picks the tab delimiter for a .tsv. So most imports are four clicks.

JSON, NDJSON, CSV and TSV are streamed rather than read whole, so memory does not grow with file size and there is no practical ceiling. Excel import is Pro, reads the first sheet, and takes row one as the column names.

Pick a write strategy deliberately

Strategy What it does
Insert Adds documents. Fails on a duplicate _id
Upsert by identity Replaces a matching document, inserts the rest
Drop and Insert Empties the collection first

Drop and Insert into a write-protected target asks for confirmation before the drop. If you are importing into production, turn write protection on before you start rather than after.

Errors: stop or continue

Stop on the first error while you are still working out whether the file is right. Switch to skip invalid records and continue once you know, and the import reports what it skipped.

The type inference traps

This is where CSV imports go wrong quietly.

  • Numbers, booleans and null are inferred when inference is on. A column of 1 and 0 becomes numbers, not booleans, unless the cells say true and false.
  • A cell holding JSON is parsed into an object or an array.
  • An empty cell imports as null, not as a missing field. Those are different in MongoDB and queries with $exists will tell them apart.
  • Dates only from an ISO-style leading YYYY-MM-DD. This is deliberate, and it is why order-1, sku-2 and Q1-2024 stay text instead of turning into dates in 2001. If your dates are 03/04/2026, they will import as strings, and that is the correct answer because nobody can tell whether that is March or April.

Type inference is one switch, on by default, and it is not offered for JSON, which already carries its types. If the inference is not what you want for a CSV, turn it off and every column imports as text, then fix the types with an update. Either way, check the result in tree view, where every value shows its BSON type, before you import the other nine files.

A whole database at once

Point the importer at a directory, one collection per file. It reports the file count before it starts. Pro.

Next