0

I am trying to run a script from windows powershell:

 .\mongo.exe  localhost:27017/test --quiet test.js

that calls mongoimport:

var c_env = 'dev';

 if (c_env === "dev") 
 { 
 ./mongoimport.exe -d noeldb -c order_notifications --file "D:\Utilities\mongodb\bin\mycollection.json";
}

I get the following error:

Tue May 29 09:47:00 SyntaxError: syntax error D:\Noel\Temp\test.js:5
failed to load: D:\Noel\Temp\test.js

Is it possible to do this?

4

1 回答 1

-1

When you run a JS script file the commands inside of it will be executed from the mongo shell.

You are doing the equivalent of:

C:\> mongo.exe
MongoDB shell
connecting to test
> ./mongoimport.exe ...

This will not work because mongo shell is expecting mongo syntax (Javascript) not Windows/powershell commands.

If you want to invoke mongoimport.exe from a script the simplest way would be to do it from a DOS/powershell script.

于 2012-05-29T10:39:59.303 回答