How to convert excel to json for mongodb import
- Step 1Export the spreadsheet as .xlsx — If your data is in Google Sheets, export via File →’ Download →’ Microsoft Excel (.xlsx). Ensure the first row contains column headers that will become MongoDB document field names.
- Step 2Drop the file and choose NDJSON output — Upload the .xlsx file and select 'NDJSON' output mode to produce one JSON object per line — the format mongoimport handles most efficiently for bulk loads.
- Step 3Review inferred types — Check that numeric fields (quantities, prices) are numbers and date columns are ISO-8601 strings. If a date column was saved as General format in Excel, re-format it as Date before converting to ensure correct detection.
- Step 4Run mongoimport or paste into Compass — Save the output as data.ndjson and run: mongoimport --db mydb --collection products --file data.ndjson. Alternatively, drag the file into MongoDB Compass's Import Data dialog and select JSON format.
Frequently asked questions
How do I preserve existing MongoDB ObjectIds from a previous export?+
Export the collection first with mongoexport --collection products --out products.json to get the _id fields, then merge that data with your Excel updates in a spreadsheet before re-importing. For fresh data, mongoimport assigns new ObjectIds automatically.
My date column exports as a serial number instead of a date string. Why?+
Excel stores dates as serial numbers internally. The converter reads the cell format metadata and converts formatted Date cells to ISO-8601 strings. If a date column was saved as General or Number format, re-format the column in Excel as Short Date before converting.
Is there a row count limit?+
There is no hard document limit — available browser memory is the practical ceiling. Files up to around 50,000 rows convert reliably in a modern browser. For larger datasets, split the sheet into 25,000-row chunks before converting and import each chunk separately.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.