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
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.
you can use upsert which will overwrite the existing. (erase+ import = overwrite with new data.)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With