Skip to content

Commit b28e4b5

Browse files
authored
DOCSP-34346 - Expanded cursor example (#160)
1 parent dc7daee commit b28e4b5

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

source/fundamentals/crud/read-operations/retrieve.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ Retrieve Data
1010
:depth: 2
1111
:class: singlecol
1212

13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: code examples, read, search, cursor
19+
1320
Overview
1421
--------
1522

@@ -216,12 +223,12 @@ To see a full list of available options, see
216223
Example
217224
~~~~~~~
218225

219-
The following example performs these actions:
226+
This example performs the following actions:
220227

221228
- Finds all documents with "Pizza" in the ``cuisine`` field
222229
- Sets the ``BatchSize`` to ``3``
223230
- Stores the results in a cursor
224-
- Prints the number of documents currently held in the cursor
231+
- Prints the documents referenced by the cursor
225232

226233
.. io-code-block::
227234
:copyable: true
@@ -230,21 +237,21 @@ The following example performs these actions:
230237
:language: csharp
231238

232239
var filter = Builders<Restaurant>.Filter.Eq("cuisine", "Pizza");
233-
234-
var findOptions = new FindOptions
235-
{
236-
BatchSize = 3
237-
};
240+
var findOptions = new FindOptions { BatchSize = 3 };
238241

239242
using (var cursor = _restaurantsCollection.Find(filter, findOptions).ToCursor())
240243
{
241-
cursor.MoveNext();
242-
Console.WriteLine($"Number of documents in cursor: {cursor.Current.Count()}");
244+
foreach (var r in cursor.ToEnumerable())
245+
{
246+
WriteLine(r.Name);
247+
}
243248
}
244249

245250
.. output::
246251

247-
Number of documents in cursor: 3
252+
Pizza Town
253+
Victoria Pizza
254+
...
248255

249256
.. tip:: Clean Up
250257

0 commit comments

Comments
 (0)