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

JavaScript switch statement execution error

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.0.0
    • Affects Version/s: 1.7.0, 1.10.6
    • Component/s: AsyncWriter
    • Labels:
      None
    • Environment:
      OS: Ubuntu 20.04
      node.js / npm versions: 10.19.0
      Additional info:
    • Developer Tools
    • Not Needed
    • Iteration Juravenator

      Problem Statement/Rationale

      The break under the switch statement in mongosh does not work, resulting in all statements after the matched case being executed

      Please be sure to attach relevant logs with any sensitive data redacted.
      How to retrieve logs for: Compass; Shell

      Steps to Reproduce

      run the following js in mongosh and watch result:

      b = 'lt'

      switch (b) { casecase : print('gt'); break; case 'lt': print('lt'); break; case 'le': print('le'); break;}

      b = 'gt'

      switch (b) { case 'gt': print('gt'); break; case 'lt': print('lt'); break; case 'le': print('le'); break;}

      b = 'le'

      switch (b) { case 'gt': print('gt'); break; case 'lt': print('lt'); break; case 'le': print('le'); break;}

      Expected Results

      The three switch statements should print 'lt', 'gt', and 'le' respectively

      Actual Results

      the first switch statement print:

      lt
      le

       

      the 2nd switch statement print:

      gt
      lt
      le

       

      the 3rd print:

      le

      Additional Notes

      Any additional information that may be useful to include.

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            sunrise_zch@163.com Robin Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: