Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14072

Shell should load .js files before --eval

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None

      Currently the shell processes --eval prior to any .js files on the command line. Is there any particular reason this order is used? I find it confusing and backwards to what I expect, probably because I think of --eval as a non-interactive replacement for the interactive REPL (unless --shell is used), and when .js files are specified without --eval they are loaded prior to presenting the prompt.

      My use case is a library of code contained in a .js file which defines some functions that I can then call from --eval. The code isn't general enough that I want to have it always loaded in my ~/.mongorc.js file. I can work around it by using load() from inside --eval, but that's ugly.

      $ cat foo.js
      print("foo");
      foo = function () { print("bar"); }
      $ mongo foo.js --eval 'foo(); print("baz")'
      MongoDB shell version: 2.4.9
      connecting to: test
      Wed May 28 12:16:43.912 ReferenceError: foo is not defined
      $ mongo --eval 'load("foo.js"); foo(); print("baz")'
      MongoDB shell version: 2.4.9
      connecting to: test
      foo
      bar
      baz
      $ 
      

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: