How to use mongoimport or any command to load multiple files

2,651 views
Skip to first unread message

Shashidhar Rao

unread,
Jan 12, 2015, 1:57:49 PM1/12/15
to mongod...@googlegroups.com
Hi,

I have used the below command to insert just one file using mongoimport under the mongo_data directory

mongoimport --db mydb --collection zip --type json --file C:\mongo_data\zips.json



Which command to use if I need to bulk insert multiple files under a directory e.g say mongo_data directory containing 100 of json files.

Is there a way out ?

Thanks in advance

Regards
Shashi

Will Berkeley

unread,
Jan 14, 2015, 10:15:57 AM1/14/15
to mongod...@googlegroups.com
mongoimport accepts one file at a time, but you can write a loop in the command prompt or a .cmd script. A .cmd script to do import all of the files in a directory looks like

for %%i in (C:\mongo_data\*) do mongoimport --file %%i --type json ==db mydb --collection zip

To run the same thing directly from the cmd line, replace %% with % because Windows.

-Will


tma...@auspicate.com

unread,
Apr 17, 2015, 5:18:44 AM4/17/15
to mongod...@googlegroups.com
Hi Will

 Even I have same requirement to import multiple files. I have done the same as suggested by you but it did not work out. Below is the script I have executed and error was %%i was unexpected at this time. Correct me if I am wrong

My script: C:\MongoDB\Server\3.0\bin>for %%i in (C:\MongoDB\Server\3.0\bin\test\*) do mongo
import --file %%i --type json == db multi --collection zip

Error: %%i was unexpected at this time.

Thanks in advance
Reply all
Reply to author
Forward
0 new messages