-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
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:
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.
- related to
-
SERVER-29091 Stop putting $readPreference inside of $queryOptions in mongos
- In Progress