@@ -42,44 +42,42 @@ object(MongoDB\Model\BSONDocument)#2 (1) {
4242
4343## Iterable Results as a Command Cursor
4444
45- Some commands, such as [ aggregate ] [ aggregate ] with the "cursor" option, may
46- return their results via an iterable command cursor. In this case, the returned
45+ Some commands, such as [ listCollections ] [ listcollections ] , return their results
46+ via an iterable command cursor. In this case, the returned
4747[ MongoDB\Driver\Cursor] [ cursor ] may be iterated in the same manner as one might
4848do with a [ Collection::find()] [ find ] query, like so:
4949
50- [ aggregate ] : http://docs.mongodb.org/manual/reference/command/aggregate /
50+ [ listcollections ] : http://docs.mongodb.org/manual/reference/command/listCollections /
5151[ find ] : ../classes/collection.md#find
5252
5353```
5454<?php
5555
5656$database = (new MongoDB\Client)->demo;
5757
58- $cursor = $database->command([
59- 'aggregate' => 'zips',
60- 'pipeline' => [
61- ['$group' => ['_id' => '$state', 'count' => ['$sum' => 1]]],
62- ['$sort' => ['count' => -1]],
63- ['$limit' => 5],
64- ],
65- 'cursor' => new \stdClass,
66- ]);
58+ $cursor = $database->command(['listCollections' => 1]);
6759
68- foreach ($cursor as $state ) {
69- printf("%s has %d zip codes\n", $state['_id '], $state['count']) ;
60+ foreach ($cursor as $collection ) {
61+ echo $collection['name '], "\n" ;
7062}
7163```
7264
7365The above example would output something similar to:
7466
7567```
76- TX has 1671 zip codes
77- NY has 1595 zip codes
78- CA has 1516 zip codes
79- PA has 1458 zip codes
80- IL has 1237 zip codes
68+ persons
69+ posts
70+ zips
8171```
8272
73+ ** Note:** at the protocol level, commands that support a cursor actually return
74+ a single result document with the essential ingredients for constructing the
75+ command cursor (i.e. the cursor's ID, namespace, and first batch of results);
76+ however, the driver's [ executeCommand()] [ executecommand ] method already detects
77+ such a result and constructs the iterable command cursor for us.
78+
79+ [ executecommand ] : http://php.net/manual/en/mongodb-driver-manager.executecommand.php
80+
8381## Specifying a Read Preference
8482
8583Some commands, such as [ createUser] [ createUser ] , can only be executed on a
0 commit comments