Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-962

use keyword is not supported in multiline input in shell

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • 2

      Problem Statement/Rationale

      Using use (or any other keyword) in multiline input (either with a file or just inputting a multiline string in Compass shell for example) in shell is not working and behavior is inconsistent based on where the statement is in the code

      Steps to Reproduce

      Try evaluating the following scripts in mongosh from a file or in Compass by just pasting them:

      use test123;
      print('hello!');
      
      print('hello');
      use test123;
      print('goodbye');
      

      Expected Results

      Both scripts work and evaluate all the lines Based on the discussion with massimiliano.marcon we don't want to support this syntax in scripts. In that case it would probably be more reasonable that both scripts throw an error, suggesting an alternative/fix for the issue (e.g., `use <db>;` is not supported in multiline inputs, please use `use('<db>');` instead or something like that)

      Actual Results

      First script will switch the database to test123 and stop
      Second script will fail with babel parsing error

      Additional Notes

            Assignee:
            Unassigned Unassigned
            Reporter:
            sergey.petushkov@mongodb.com Sergey Petushkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: