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

Remove shell support for $query/query "wrapped" commands

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Minor Change
    • QE 2021-12-27, QE 2022-01-10, QE 2022-11-14, QE 2022-11-28

      For reasons that I do not fully understand, but which presumably derive from the format once used for OP_QUERY commands, the shell supports the following:

      MongoDB Enterprise > db.runCommand({$query: {ping: 1}})
      { "ok" : 1 }
      MongoDB Enterprise > db.runCommand({query: {ping: 1}})
      { "ok" : 1 }
      

      These are both identical to db.runCommand({ping: 1}). All three shell commands cause the shell to issue an OP_MSG command with the payload in the "unwrapped" form {ping: 1}. Neither the wrapped form nor OP_QUERY commands in general are supported by the 5.1 server, so the concept of a "wrapped" command exists exclusively in the legacy shell.

      It appears that the shell has JS code in a number of places to handle commands that are wrapped inside query or $query fields. On the vanilla runCommand() path, the wrapped format is handled here:

      https://github.com/mongodb/mongo/blob/7770140bab60c531ed4c20a40514a1a625b1cb5c/src/mongo/shell/session.js#L172-L178

      There is really no reason for this behavior, as far as I'm aware. In order to simplify the code base, we should remove the shell's handling for the "wrapped" command format and migrate any tests using this format to the more typical "unwrapped" format. In other words, an instance of {$query: {ping: 1}} in a test should be simplified to {ping: 1}. I don't think we have to worry about the implications of this change for end users, as the mongo shell is deprecated for use by end users in favor of mongosh.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: