@@ -34,7 +34,7 @@ Execute a Command
34
34
-----------------
35
35
36
36
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
38
38
command execution method. The {+driver-short+} provides the following methods
39
39
to run database commands:
40
40
@@ -55,17 +55,54 @@ the current member's role in the replica set, on a database:
55
55
For a full list of database commands and corresponding parameters, see
56
56
the :ref:`Additional Information section <addl-info-runcommand>`.
57
57
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
+
58
101
.. note:: Read Preference
59
102
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.
69
106
70
107
The following code shows how to specify a read preference and pass it
71
108
as an option to the ``command()`` method:
@@ -178,6 +215,7 @@ For more information about the concepts in this guide, see the following documen
178
215
- :manual:`db.runCommand() </reference/method/db.runCommand/>`
179
216
- :manual:`Database Commands </reference/command/>`
180
217
- :manual:`hello Command </reference/command/hello/>`
218
+ - :manual:`find Command </reference/command/find/>`
181
219
182
220
.. - :manual:`checkMetadataConsistency Command </reference/command/checkMetadataConsistency/>`
183
221
0 commit comments