MongoDB Bulk imports using mongoimport from a Windows folder

I have many json files in the archive, and I need to import them into mongo in one operation (I think it could be in a loop). Do you have any ideas about this?

+8
json mongodb mongoimport
source share
4 answers

If you are in a Linux / Unix shell, you can try

for filename in *; do mongoimport -d mydb -c $filename; done 

If you are on Windows:

 FOR %i IN (C:\mongodbData\*.json) DO mongoimport --db dbName --collection colection --type json --file %i 
+15
source share

You need to use mongorestore to recover from a dump created by mongoexport

http://docs.mongodb.org/v2.6/reference/program/mongorestore/

eg

mongorestore --drop --oplogReplay mongodb/

+2
source share

You can use this:

 FOR %i IN (<data folder>\*.json) DO mongoimport -d <database> -c <collection> --file %i 
0
source share

mongorestore imports all exported mongodb files

 cd C:\Program Files\MongoDB\Server\4.0\bin mongorestore.exe -d <db name> C:\Users\Mike\Downloads\myProject\ 

But if you really want to import all only JSON meta files without .bson

 cd C:\Users\Mike\Downloads\myProject\ FOR %i IN (*.json) DO "C:\Program Files\MongoDB\Server\4.0\bin\mongoimport.exe" --db <db name> --collection %~ni --type json --file %i 

This is a sample of work on Windows 10

0
source share

All Articles