@@ -21,10 +21,10 @@ statistics, initializing a replica set, or running an aggregation pipeline.
2121This guide includes the following sections:
2222
2323- :ref:`Execute a Command <rust-execute-command>` describes the syntax
24- and behavior of the ``run_command()`` method
24+ and behavior of the ``run_command()`` and ``run_cursor_command()`` methods
2525
2626- :ref:`Response <rust-command-response>` describes the information
27- that the ``run_command()`` method returns
27+ that the command execution methods return
2828
2929- :ref:`Command Example <rust-command-example>` provides a command
3030 example and describes the output for the command
@@ -51,8 +51,15 @@ Execute a Command
5151-----------------
5252
5353To run a database command, you must specify the command and any relevant
54- parameters in a command document, then pass the command document to the
55- ``run_command()`` method.
54+ parameters in a command document, then pass the command document to a
55+ command execution method. The {+driver-short+} provides the following methods
56+ to run database commands:
57+
58+ - ``run_command()``, which returns the command response as a
59+ ``Document`` type. You can use this method with any database command.
60+ - ``run_cursor_command()``, which returns the command response as an iterable
61+ ``Cursor`` type. You can use this method only if your database command
62+ returns multiple result documents.
5663
5764The following code shows how you can use the ``run_command()``
5865method to run the ``hello`` command, which returns information about
@@ -62,28 +69,43 @@ the current member's role in the replica set, on a database:
6269
6370 let result = my_db.run_command(doc! { "hello": 1 }, None).await?;
6471
72+ The ``checkMetadataConsistency`` command returns multiple result
73+ documents. You can use the ``run_cursor_command()`` method to run
74+ this command and collect the results, as shown in the following code:
75+
76+ .. code-block:: rust
77+
78+ let cursor = my_db
79+ .run_cursor_command(doc! { "checkMetadataConsistency": 1 }, None)
80+ .await?;
81+
6582To find a link to a full list of database commands and corresponding
6683parameters, see the :ref:`Additional Information section
6784<rust-addtl-info-runcommand>`.
6885
6986.. note:: Read Preference
7087
71- The ``run_command()`` method does not obey the read preference you
72- might have set on your ``Database`` object elsewhere in your code. By
73- default, it uses the ``primary`` read preference.
88+ The ``run_command()`` and ``run_cursor_command()`` methods do not
89+ obey the read preference you might have set on your ``Database``
90+ object elsewhere in your code. By default, they use the ``primary``
91+ read preference.
7492
7593 You can set a read preference for command execution by
76- passing an options object. The following code shows how to specify a
77- read preference in a ``SelectionCriteria`` instance and pass it as an
78- option to the ``run_command()`` method:
94+ passing an options object to either method . The following code shows
95+ how to specify a read preference in a ``SelectionCriteria`` instance
96+ and pass it as an option to the ``run_command()`` method:
7997
8098 .. code-block:: rust
8199
82- let command_options: SelectionCriteria = SelectionCriteria::ReadPreference(
100+ let command_options = SelectionCriteria::ReadPreference(
83101 ReadPreference::Primary
84102 );
85103 let result = my_db.run_command(command_doc, command_options).await?;
86104
105+ The ``run_cursor_command()`` method takes a
106+ ``RunCursorCommandOptions`` instance as a parameter. You can set the
107+ ``selection_criteria`` field of this struct to select a read preference.
108+
87109 For more information on read preference options, see :manual:`Read
88110 Preference </core/read-preference/>` in the Server manual.
89111
@@ -92,11 +114,14 @@ parameters, see the :ref:`Additional Information section
92114Response
93115--------
94116
95- The ``run_command()`` method returns a ``Document`` instance that contains
96- the response from the database after the command runs. Each
97- database command performs a different function, so the response content
98- can vary across commands. However, every response contains a document
99- with the following fields:
117+ The ``run_command()`` method returns a ``Document`` object that contains
118+ the response from the database after the command has been executed. The
119+ ``run_cursor_command()`` returns a ``Cursor`` that references multiple
120+ result documents.
121+
122+ Each database command performs a different function, so the response
123+ content can vary depending on the command executed. However, every
124+ response contains a document with the following fields:
100125
101126.. list-table::
102127 :header-rows: 1
@@ -214,5 +239,7 @@ API Documentation
214239~~~~~~~~~~~~~~~~~
215240
216241- `run_command() <{+api+}/struct.Database.html#method.run_command>`__
242+ - `run_cursor_command() <{+api+}/struct.Database.html#method.run_cursor_command>`__
217243- `SelectionCriteria <{+api+}/options/enum.SelectionCriteria.html>`__
244+ - `RunCursorCommandOptions <{+api+}/options/struct.RunCursorCommandOptions.html>`__
218245- `ReadPreference <{+api+}/options/enum.ReadPreference.html>`__
0 commit comments