@@ -15,7 +15,9 @@ Definition
15
15
16
16
.. phpmethod:: MongoDB\\Database::command()
17
17
18
- Execute a :manual:`command </reference/command>` on the database.
18
+ Execute a :manual:`command </reference/command>` on the database. This is
19
+ generally used to execute commands that do not have a corresponding helper
20
+ method within the library.
19
21
20
22
.. code-block:: php
21
23
@@ -43,9 +45,10 @@ Errors/Exceptions
43
45
Example
44
46
-------
45
47
46
- The following example executes a :manual:`ping
47
- </reference/command/ping>` command, which returns a cursor with a single
48
- result document:
48
+ Most database commands return a single result document, which can be obtained by
49
+ converting the returned cursor to an array and accessing its first element. The
50
+ following example executes a :manual:`ping </reference/command/ping>` command
51
+ and prints its result document:
49
52
50
53
.. code-block:: php
51
54
@@ -55,7 +58,7 @@ result document:
55
58
56
59
$cursor = $database->command(['ping' => 1]);
57
60
58
- var_dump($c ->toArray()[0]);
61
+ var_dump($cursor ->toArray()[0]);
59
62
60
63
The output would resemble:
61
64
@@ -69,9 +72,11 @@ The output would resemble:
69
72
}
70
73
}
71
74
72
- The following example executes a :manual:`listCollections
73
- </reference/command/listCollections>` command, which returns a cursor with
74
- multiple result documents:
75
+ Some database commands return a cursor with multiple results. The following
76
+ example executes :manual:`listCollections </reference/command/listCollections>`,
77
+ which returns a cursor containing a result document for each collection in the
78
+ ``test`` database. Note that this example is illustrative; applications would
79
+ generally use :phpmethod:`MongoDB\\Database::listCollections()` in practice.
75
80
76
81
.. code-block:: php
77
82
@@ -81,7 +86,7 @@ multiple result documents:
81
86
82
87
$cursor = $database->command(['listCollections' => 1]);
83
88
84
- var_dump($c ->toArray());
89
+ var_dump($cursor ->toArray());
85
90
86
91
The output would resemble:
87
92
0 commit comments