My Coding > Databases > MongDB > MongoDB: import

MongoDB: import

MongoDB have some tools for importing CSV and JSON datafiles. In this example we will import one of the standard dataset IRIS

Import with mongoimport

mongoimport is a standard tool for import datasets into MongDB. When mongodb database is installed, this tool is installed also

Import CSV file

We will use mongoimport to import file iris.csv. We will create or use database intro_db and in this database we will create collection iris1. File type is csv and we are using header line from this file:


> mongoimport --db intro_db --collection iris1 --type csv --headerline --file iris.csv

2021-12-23T06:19:29.466+0000	connected to: mongodb://localhost/
2021-12-23T06:19:29.835+0000	150 document(s) imported successfully.
0 document(s) failed to import.

Import JSON file

Importing JSON file is pretty similar to importuning CSV file, but JSON is more natural for MongoDB and as are result, the command line will be a bit simplier


> mongoimport --db intro_db --collection iris2 --type json --file iris.json --jsonArray

2021-12-23T06:25:59.230+0000	connected to: mongodb://localhost/
2021-12-23T06:25:59.507+0000	150 document(s) imported successfully.
0 document(s) failed to import.


Published: 2021-12-23 06:08:05
Updated: 2021-12-23 06:30:25

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.