@@ -36,7 +36,9 @@ statistics, initializing a replica set, or running an aggregation pipeline.
36
36
that might not be available in the library.
37
37
38
38
If there are no available helpers in the library or the shell, you
39
- can use the ``db.runCommand()`` shell method.
39
+ can use the ``db.runCommand()`` shell method or the library's
40
+ ``MongoDB\Database::command()`` method, which is described in this
41
+ guide.
40
42
41
43
.. _php-execute-command:
42
44
@@ -47,12 +49,11 @@ To run a database command, you must specify the command and any relevant
47
49
parameters in a command document, then pass the command document to the
48
50
``MongoDB\Database::command()`` method. Many database commands return
49
51
multiple result documents, so the ``command()`` method returns a
50
- ``Cursor`` object that you can iterate through.
52
+ ``MongoDB\Driver\ Cursor`` object that you can iterate through.
51
53
52
54
The following code shows how you can use the ``command()``
53
55
method on a :phpclass:`MongoDB\Database` instance to run the ``hello``
54
- command, which returns information about the current member's role in
55
- the replica set:
56
+ command, which returns information about the server:
56
57
57
58
.. literalinclude:: /includes/write/run-command.php
58
59
:language: php
@@ -66,7 +67,7 @@ parameters, see the :ref:`Additional Information section
66
67
67
68
.. note:: Read Preference
68
69
69
- The ``command()`` method does not obey the read preference you might
70
+ The ``command()`` method does not inherit the read preference you might
70
71
have set on your ``Database`` instance elsewhere in your code. By
71
72
default, ``command()`` uses the ``primary`` read preference.
72
73
@@ -90,8 +91,12 @@ Response
90
91
The ``command()`` method returns a ``Cursor`` object that contains
91
92
the response from the database for the given command. Each database
92
93
command performs a different function, so the response
93
- content can vary. Some command responses contain multiple result
94
- documents. In these situations, the library converts the cursor
94
+ content can vary.
95
+
96
+ For commands that return a single result document,
97
+ that result is available as the first and only document in the
98
+ cursor. For commands that return multiple result
99
+ documents, the library converts the cursor
95
100
envelope in the raw command response, which includes the cursor ID and
96
101
the first batch of results, into an iterable cursor.
97
102
@@ -101,11 +106,6 @@ results or extracts the first and only document in the cursor. See the
101
106
:ref:`php-addtl-info-runcommand` section of this guide to find a link to
102
107
the full list of database commands.
103
108
104
- If the number of documents in the command response is sufficiently large, you
105
- can run a :manual:`getMore </reference/command/getMore/>` command to
106
- retrieve the next batch of results from the cursor by using the cursor
107
- ID.
108
-
109
109
The raw command response contains the following fields:
110
110
111
111
.. list-table::
0 commit comments