Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Bulk import using mongoimport from Windows folder

I have a lot of json files in archive and i need to import them into mongo per one operation (i think that it might be in cycle). Have you any ideas about this?

like image 415
user3306125 Avatar asked Mar 04 '14 09:03

user3306125


People also ask

How do I import data into Mongoimport?

If you have CSV files (or TSV files - they're conceptually the same) to import, use the --type=csv or --type=tsv option to tell mongoimport what format to expect. Also important is to know whether your CSV file has a header row - where the first line doesn't contain data - instead it contains the name for each column.

How do I import multiple CSV files into MongoDB?

You can use the mongoimport command to import CSV files into a collection using the headerline option. Headerline option notifies the mongoimport command of the first line; to be not imported as a document since it contains field names instead of data.


1 Answers

If you are in a Linux/Unix shell you can try

for filename in *; do mongoimport -d mydb -c $filename;  done

If you are on Windows:

FOR %i IN (C:\mongodbData\*.json) DO mongoimport --db dbName --collection colection --type json --file %i
like image 54
Sumeet Kumar Yadav Avatar answered Sep 20 '22 14:09

Sumeet Kumar Yadav