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?
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?
There is a pymongo extention utilities package, one of the modules there does exactly this, imports an excel file to a mongo collection or a complete excel workbook to a mongo database. You can find documentation and examples here:
and you can install the library with `pip install mongoUtils
You can upload data of multiple sheets from one excel into mongodb at once using this code.
Your first row i.e "0" row will be consider as column title and rest data of that column.
mongoimport -d admin -c Mongocsv --type csv --file Mongocsv.csv --headerline
connected to: 127.0.0.1 imported 5 objects
mongo
You can handle loading the Excel file content by writing Java code using Apache POI library (https://poi.apache.org/). The library is developed for working with MS office application data including Excel.
I have recently created the application based on the technology that will help you to load Excel files to the MongoDB database.
The application is available under http://www.abespalov.com/ and tested only for Windows, but should work for Linux as well. The application will create necessary collection automatically and populate the collection with the Excel file content. You can export several files in parallel. You can skip the step to convert the files into the CSV format. The application handles the xls and xlsx formats.
Overall application stages are :
1) Load the excel file content. Here is the code depending on file extension:
2) Establish the MongoDB connection. I use the MongoClientURI library;
3) Iterate over the sheet and inset rows into the collection. Here is a piece of Java code :
Here you can find all Java code for the application created for exporting excel to Postgres (https://github.com/palych-piter/Excel2DB).
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 formongoimport
here, but in any case, the command you need to run should look something like the following: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.I used "fast-csv" to upload csv onto mongoDB database.
Sample Code: