0

New to Mongo, just experimenting w the shell on a Windows XP machine running Mongo 2.0.1.

At the ">" mongo.exe cmd prompt, what do I enter in order to read cmds from another file called TEST.js ? I put a TEST.js file every place I could think of, and typed things like ">./mongo TEST.js", ">.mongo full-pathname.js", ">TEST.js", etc.

Is there a way to do this ?

(Why?: I loaded a bunch of data w mongoimport & thought I could try a quick-and-dirty mapreduce from the > shell prompt prior to setting up via a ruby or python driver & doing it the right way. The map,reduce & finalize funcs are sitting in a *.js file, and I need those function defs imported before I can run the mapreduce method on my data collection.)

1 Answer 1

5

From the Windows XP command prompt, you can run the mongo shell (mongo.exe in Windows) with the "--shell" option followed by your filespec to start the mongo shell, load your file and then remain in the mongo shell. If your file defines "map" and "reduce" functions, those will be available to you at the mongo shell's prompt.

For example, "mongo --shell TEST.js" .

Alternatively, you can start the mongo shell and then issue a "load" command to load your JavaScript file. The command 'load("TEST.js")' should do it for you.

If these are functions you will want every time you start the mongo shell, you can put the JavaScript into a file named ".mongorc.js" (note the initial period) in your "user" directory, for example "C:\Documents and Settings\YourName\.mongorc.js" on Windows XP when logged in as YourName. The .mongorc.js feature was introduced in version 1.9, so your version has it.

1
  • That's it thanks. Requires escaped \'s as in load("dir\\dir\\file.js"), and by default looks in windows curr dir.
    – tpascale
    Nov 22, 2011 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.