Skip to content

Instantly share code, notes, and snippets.

@fabien0102
Created March 15, 2015 09:33
Show Gist options
  • Save fabien0102/88dcaa184d801fd5e67a to your computer and use it in GitHub Desktop.
Save fabien0102/88dcaa184d801fd5e67a to your computer and use it in GitHub Desktop.
Import multiple json files into mongoDB
ls -1 *.json | while read jsonfile; do mongoimport -d support -c logs -file $jsonfile --jsonArray -type json; done
@wjrivera
Copy link

Nice, thank you!

@ausiddiqui
Copy link

Cheers @fabien0102 this is still very relevant! Saved me a bunch of time!

@rajsekhar8099
Copy link

when i tried to i got some eror like
2017-07-27T10:56:41.762-0400 error parsing command line options: unknown option "type"
2017-07-27T10:56:41.762-0400 try 'mongoimport --help' for more information
2017-07-27T10:56:41.770-0400 error parsing command line options: unknown option "type"
2017-07-27T10:56:41.770-0400 try 'mongoimport --help' for more information
how i can upload bunch of .jsonfiles from particular folder suppose my folder location is /home/hades3/Desktop/converter/ ,data base name 'test' and collection is docs.

do i need to change the .json files name in accordance with collection name like docs1,docs2,docs3....

@shelune
Copy link

shelune commented Feb 13, 2018

The way at the moment is:
ls -1 *.json | while read jsonfile; do mongoimport -h <HOST> -d <DB> -c <COLLECTION> -u <username> -p <password> --file $jsonfile --jsonArray --type json; done

Missing some dashes.

@saloni-jain484
Copy link

saloni-jain484 commented Oct 1, 2020

how to execute script in windows machine?? As in command prompt linux command will not work
@fabien0102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment