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

How can I elegantly switch db context in a .js file?

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I'm working in room 5025 if you want to come chat.

      Context: Previously, in version 2.4, our javascript parser would allow me to pass javascript files with shell commands such as "use agg" to switch context to the agg database.

      Problem: In the 2.6.0 shell, I can't pass the shell .js files with "use agg" because it isn't valid javascript.

      Instead, I'm reassigning db with something like

      db = new Mongo().getDB("agg")
      

      but this causes its own problems. For instance, if I have test.js:

      db = new Mongo().getDB("agg")
      db.foo.insert( { a : 1 } )
      

      then if I type mongo test.js, I get:

      $ mongo test.js
      MongoDB shell version: 2.6.0
      connecting to: test
      

      This is confusing for students taking the class.

      I can type

       
      mongo agg test.js
      MongoDB shell version: 2.6.0
      connecting to: agg
      

      but the agg is doing nothing.

      Is there any elegant way to specify, in a .js file, which database we're dealing with in a way that's consistent with the behavior of the script?

            Assignee:
            Unassigned Unassigned
            Reporter:
            william.cross William Cross
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: