The data is still a spreadsheet

FileToMongo » Use cases » Load a spreadsheet into MongoDB

Download FileToMongo Free Trial »     Buy FileToMongo Now »

The situation

A department hands over an export, a system produces CSV because that is what it has always produced, or the reference data for a new collection exists as an Excel workbook on somebody's desktop. The destination is MongoDB, and the intermediate step everybody dreads is rewriting the file as JSON by hand.

Two things usually go wrong on the way: the columns have to be turned into fields, and the text arrives as mojibake because the file was written by a Windows program in a code page nobody mentioned.

What you do

  1. Choose the file - CSV, TSV, TXT, Excel, JSON, JSONL, XML, HTML, RDF or SQL - and the delimiter if it is a text file.
  2. Leave Encoding on Auto Detect (UTF-8, GBK, ISO-8859-1 and the rest are recognised), or set it explicitly when you know what the file is.
  3. Because Field Name In File Header is on, the field names are taken from the first row - check the preview grid, which shows exactly what will be written.
  4. Connect to MongoDB, choose the collection (an existing one, or a new one) and run.

Configuring a CSV import in FileToMongo, with encoding detection and the header row used for field names

Millions of rows are streamed rather than held in memory, so the size of the file is a matter of patience rather than of RAM. None of it leaves the machine: the file is read locally and the documents are written to the MongoDB server you name.

What it will not do

Related

Many files at once: one collection per file, or all of them into one collection. The single-file mode: file to collection. Why not mongoimport: FileToMongo or mongoimport. Doing it repeatedly: sessions, command line.