0

I'm trying to import all csv files in a folder into those many MongoDB collections (with same names as the file names). I'm trying to do it through command line (mongo.exe).

I've written the following for loop but I can't seem to get the syntax right.

>FOR /R %G in (filepath\...\NYSE\*.csv) DO mongoimport --d nyseDb --c %G --type csv --file %G --headerline

The following error was showed up.

E QUERY    [thread1] SyntaxError: missing ) in parenthetical @(shell):1:16

I've looked up many places to find corrections, but none of them worked.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • Doesn't `FOR /R %G in (filepath\...\NYSE\*.csv) do echo %G` issue the entire path to file in the output? Given that you are passing that value as a "collection name" to `mongoimport` I'm certain you don't want that. Surely you just want the "base" file name without the ".csv" file extention. As a basic principle `/r` which means recursive seems dangerous in this context as well. – Neil Lunn May 26 '17 at 03:28
  • Always quote paths in `FOR` loops. `"%~G"` Also, do any of your .csv file names contain parentheses characters? – lit May 26 '17 at 16:27

0 Answers0