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.
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.
Dump command: mongodump –host localhost:27017 –gzip –db Alex –out ./testSO Restore Command: mongorestore –host localhost:27017 –gzip –db Alex ./testSO/Alex Works perfectly! While using archive: Dump command: mongodump –host localhost:27017 –archive=dump.gz –gzip –db Alex Restore Command: mongorestore –host localhost:27017 –gzip –archive=dump.gz –db Alex Note:- While using archive you need to stick with the database name. Different … Read more
The counterpart to mongodump is mongorestore (and the counterpart to mongoimport is mongoexport) — the major difference is in the format of the files created and understood by the tools (dump and restore read and write BSON files; export and import deal with text file formats: JSON, CSV, TSV. If you’ve already run mongodump, you … Read more
I just figured out. I had a JSON Array in the file, and for that, I had to append –jsonArray It is documented here with the URL provided.
Your example worked for me with MongoDB 1.6.3 and 1.7.3. Example below was for 1.7.3. Are you using an older version of MongoDB? $ cat > locations.csv Name,Address,City,State,ZIP Jane Doe,123 Main St,Whereverville,CA,90210 John Doe,555 Broadway Ave,New York,NY,10010 ctrl-d $ mongoimport -d mydb -c things –type csv –file locations.csv –headerline connected to: 127.0.0.1 imported 3 objects … Read more
Your example worked for me with MongoDB 1.6.3 and 1.7.3. Example below was for 1.7.3. Are you using an older version of MongoDB? $ cat > locations.csv Name,Address,City,State,ZIP Jane Doe,123 Main St,Whereverville,CA,90210 John Doe,555 Broadway Ave,New York,NY,10010 ctrl-d $ mongoimport -d mydb -c things –type csv –file locations.csv –headerline connected to: 127.0.0.1 imported 3 objects … Read more
I was able to fix the error using the following query: mongoimport –db dbName –collection collectionName –file fileName.json –jsonArray Hopefully this is helpful to someone.