Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import more than 1 json file using mongoimport

I am new to mongodb and want to know about importing a json file from one server to another. I tried the following command mongoimport -d test -c bik check.json and it works fine for me. Now i want to know when there are multiple json files how do i import all of them at a single go. I could not find any related document where it is written this is not possible. Please help me is this possible and how

like image 538
user850234 Avatar asked Jul 23 '12 09:07

user850234


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.

Does Mongoimport overwrite?

you can use upsert which will overwrite the existing. (erase+ import = overwrite with new data.)

Can we import JSON in MongoDB?

The process to import JSON into MongoDB depends on the operating system and the programming language you are using. However, the key to importing is to access the MongoDB database and parsing the file that you want to import. You can then go through each document sequentially and insert into MongoDB.


1 Answers

I came up with a more elegant way to automatically import ALL collections:

ls -1 *.json | sed 's/.json$//' | while read col; do      mongoimport -d db_name -c $col < $col.json;  done 

I hope this is helpful.

like image 165
romaninsh Avatar answered Sep 17 '22 04:09

romaninsh