Import more than 1 json file using mongoimport Import more than 1 json file using mongoimport json json

Import more than 1 json file using mongoimport


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.


You can always write some shell scripts.

colls=( mycoll1 mycoll2 mycoll5 )for c in ${colls[@]}do  mongoimport -d mydb -c $c.jsondone


Windows Batch version:

@echo offfor %%f in (*.json) do (    "mongoimport.exe" --jsonArray --db databasename --collection collectioname --file %%~nf.json)