Skip to content

Commit f8fa613

Browse files
committed
JT feedback
1 parent fcecd1f commit f8fa613

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

source/read/cursor.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ To learn how to create a free MongoDB Atlas cluster and load the sample datasets
5353
Access Cursor Contents Iteratively
5454
----------------------------------
5555

56-
To iterate over the contents of a ``MongoDB\Driver\Cursor`` instance, use a ``foreach`` loop.
56+
The ``MongoDB\Driver\Cursor`` class implements the ``Iterator`` interface, so you
57+
can use a ``foreach`` loop to iterate through its contents.
5758

5859
The following example uses the ``MongoDB\Collection::find()`` method to retrieve all documents
5960
in which the ``name`` field value is ``'Dunkin' Donuts'``. It then prints each document from the
@@ -111,8 +112,14 @@ Retrieve All Documents
111112
application memory, your program will crash. If you expect a large result
112113
set, :ref:`access your cursor iteratively <php-cursors-iterate>`.
113114

114-
To retrieve all documents from a cursor, convert the cursor into an array. The following
115-
example calls the ``toArray()`` method on a cursor to store its results in an array:
115+
To retrieve all documents from a cursor, convert the cursor into an array by using
116+
either of the following methods:
117+
118+
- ``MongoDB\\Driver\\Cursor::toArray()``: Call on a ``MongoDB\Driver\Cursor`` object
119+
- ``iterator_to_array()``: Pass a ``MongoDB\Driver\Cursor`` object as a parameter
120+
121+
The following example calls the ``toArray()`` method on a cursor to store its results
122+
in an array:
116123

117124
.. literalinclude:: /includes/read/cursor.php
118125
:language: php
@@ -172,6 +179,7 @@ To learn more about cursors, see the following pages in the PHP manual:
172179
- `MongoDB\\Driver\\Cursor <{+php-manual+}/class.mongodb-driver-cursor.php>`__
173180
- `MongoDB\\Driver\\Cursor::current() <{+php-manual+}/mongodb-driver-cursor.current.php>`__
174181
- `MongoDB\\Driver\\Cursor::toArray() <{+php-manual+}/mongodb-driver-cursor.toarray.php>`__
182+
- `iterator_to_array() <{+php-manual+}/function.iterator-to-array.php>`__
175183

176184
API Documentation
177185
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)