Skip to content

Commit 2119386

Browse files
authored
DOCSP-31487: removed options for command() v6 (#737)
* DOCSP-31487: removed options for command() v6 * partial address of CC PR comments * CC PR fixes all comments addressed * small fixes * fix * CC PR fixes 2 * small fix * CC PR fixes 3 * CC suggestion
1 parent a5295f7 commit 2119386

File tree

4 files changed

+90
-24
lines changed

4 files changed

+90
-24
lines changed

source/fundamentals/run-command.txt

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Execute a Command
3434
-----------------
3535

3636
To run a database command, you must specify the command and any relevant
37-
parameters in a command document, then pass the command document to a
37+
parameters in a document, then pass this document to a
3838
command execution method. The {+driver-short+} provides the following methods
3939
to run database commands:
4040

@@ -55,17 +55,54 @@ the current member's role in the replica set, on a database:
5555
For a full list of database commands and corresponding parameters, see
5656
the :ref:`Additional Information section <addl-info-runcommand>`.
5757

58+
.. _node-command-options:
59+
60+
Command Options
61+
---------------
62+
63+
You can specify optional command behavior for the ``command()``
64+
and ``runCursorCommand()`` methods.
65+
66+
The ``command()`` method accepts a ``RunCommandOptions`` object. To learn
67+
more about the ``RunCommandOptions`` type, see the `API documentation <{+api+}/types/RunCommandOptions.html>`__.
68+
69+
The ``runCursorCommand() method`` accepts a ``RunCursorCommandOptions``
70+
object. To learn more about the ``RunCursorCommandOptions`` type, see
71+
the `API documentation <{+api+}/types/RunCursorCommandOptions.html>`__.
72+
73+
Starting in version 6.0 of the {+driver-short+}, you can pass only the
74+
following options to the ``command()`` method:
75+
76+
- ``comment``
77+
- ``enableUtf8Validation``
78+
- ``raw``
79+
- ``readPreference``
80+
- ``session``
81+
82+
You can set additional options in the document that you pass to
83+
the ``command()`` method. To learn more about a command and the
84+
additional options that it accepts, locate the command and follow the
85+
link on the :manual:`Database Commands </reference/command/>` section of
86+
the Server manual.
87+
88+
The following code shows how to specify a ``grantRolesToUser`` command
89+
that executes with a ``majority`` write concern:
90+
91+
.. code-block:: javascript
92+
:emphasize-lines: 4
93+
94+
const commandDoc = {
95+
grantRolesToUser: "user011",
96+
roles: [ "readWrite" ],
97+
writeConcern: { w: "majority" }
98+
};
99+
const result = await myDB.command(commandDoc);
100+
58101
.. note:: Read Preference
59102

60-
``command()`` and ``runCursorCommand()`` do not obey the read
61-
preference you may have set on your ``Db`` object elsewhere in
62-
your code. By default, these methods use the ``primary`` read
63-
preference.
64-
65-
You can set a read preference for command execution by
66-
passing an options object to either method. The ``command()`` method
67-
takes a ``RunCommandOptions`` object, and the ``runCursorCommand()`` method
68-
takes a ``RunCursorCommandOptions`` object.
103+
The ``command()`` and ``runCursorCommand()`` methods ignore
104+
the read preference setting you may have set on your ``Db`` object.
105+
By default, these methods use the ``primary`` read preference.
69106

70107
The following code shows how to specify a read preference and pass it
71108
as an option to the ``command()`` method:
@@ -178,6 +215,7 @@ For more information about the concepts in this guide, see the following documen
178215
- :manual:`db.runCommand() </reference/method/db.runCommand/>`
179216
- :manual:`Database Commands </reference/command/>`
180217
- :manual:`hello Command </reference/command/hello/>`
218+
- :manual:`find Command </reference/command/find/>`
181219

182220
.. - :manual:`checkMetadataConsistency Command </reference/command/checkMetadataConsistency/>`
183221

source/upgrade.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Version 6.x Breaking Changes
7070
``tlsCertificateKeyFile`` connection options when you call the
7171
``MongoClient.connect()`` method, not when you create the
7272
``MongoClient`` instance.
73+
- The ``Db.command()`` method accepts only options that are not related
74+
to a specific command. To learn more about these options, see the
75+
:ref:`Command Options <node-command-options>` section of the Run a
76+
Command guide.
7377
- If you add ``mongodb-client-encryption`` as a dependency,
7478
the major version number must match that of the {+driver-short+}. For example,
7579
{+driver-short+} v6.x.x requires ``mongodb-client-encryption`` v6.x.x.

source/usage-examples/command.txt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
Run a Command
55
=============
66

7-
You can run all raw database operations using the
8-
`db.command() <{+api+}/classes/Db.html#command>`__ method. Call the ``command()`` method with
9-
your command object on an instance of a database for diagnostic and
10-
administrative tasks such as fetching server stats or initializing a replica
11-
set.
12-
13-
.. note::
14-
Use the :mongosh:`MongoDB Shell </>` for administrative tasks instead of
15-
the {+driver-short+} whenever possible.
16-
17-
You can specify additional options in the ``options`` object passed in
18-
the second parameter of the ``command()`` method. For more information
19-
on the options you can pass, see the
20-
`db.command() API documentation <{+api+}/classes/Db.html#command>`__.
7+
You can execute database commands by using the
8+
`command() <{+api+}/classes/Db.html#command>`__ method on a ``Db``
9+
instance.
10+
11+
You can specify a command and options in a document. To run the
12+
command, pass this document to the ``command()`` method. To see a full
13+
list of database commands, see :manual:`Database Commands
14+
</reference/command/>` in the Server manual.
15+
16+
.. tip::
17+
18+
Use the :mongosh:`MongoDB Shell </>` for administrative tasks instead of
19+
the {+driver-short+} whenever possible.
20+
21+
You can specify optional command behavior by passing a
22+
``RunCommandOptions`` object to the ``command()`` method. To learn more
23+
about the supported options, see the
24+
`Db.command() API documentation <{+api+}/classes/Db.html#command>`__.
2125

2226
Example
2327
-------

source/whats-new.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ The {+driver-short+} v6.0 release includes the following features:
110110
the ``MongoClient.connect()`` method, not when you create a
111111
``MongoClient`` instance.
112112

113+
- Removes the following options for the ``Db.command()`` method:
114+
115+
- ``willRetryWrite``
116+
- ``omitReadPreference``
117+
- ``writeConcern``
118+
- ``explain``
119+
- ``readConcern``
120+
- ``collation``
121+
- ``maxTimeMS``
122+
- ``comment``
123+
- ``retryWrites``
124+
- ``dbName``
125+
- ``authdb``
126+
- ``noResponse``
127+
128+
Although you cannot pass these options to the
129+
``Db.command()`` method, you can still set them in the command
130+
document. To learn more, see the :ref:`Command Options
131+
<node-command-options>` section of the Run a Command guide.
132+
113133
.. _version-5.8:
114134

115135
What's New in 5.8

0 commit comments

Comments
 (0)