how to import excel file (XLSX) to mongoDB

SUNDARRAJAN K picture SUNDARRAJAN K · Aug 11, 2014 · Viewed 66.9k times · Source

I have a set of data as input to be given to MongoDB in XLSX format. How am I supposed to import the Excel file as input to MongoDB?

Is there any plugin available to import xlsx files as input to MongoDB?

Answer

Juan Carlos Farah picture Juan Carlos Farah · Aug 11, 2014

You cannot import an XLSX file into MongoDB directly. However, what you can do with an Excel spreadsheet is save it as a CSV file, then use mongoimport to import it into MongoDB. You can find the documentation for mongoimport here, but in any case, the command you need to run should look something like the following:

mongoimport --db myDb --collection myCollection --type csv --headerline --file /path/to/myfile.csv

In the command above, the --headerline flag indicates that the first line in your file contains the name of the fields. There are many other options you can use depending on your needs. These are highlighted in the documentation.