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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 6.0 Desired
    • Component/s: None
    • Labels:
      None
    • Sprint:
      QE 2021-12-27, QE 2022-01-10

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            backlog-query-execution Backlog - Query Execution
            Reporter:
            david.storch David Storch
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: