File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed
includes/fundamentals/code-examples Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,9 @@ A cursor is a mechanism that returns the results of a read operation in iterable
27
27
batches. Because a cursor holds only a subset of documents at any given time,
28
28
cursors reduce both memory consumption and network bandwidth usage.
29
29
30
- You can retrieve a cursor by using the ``FindSync()`` and ``FindAsync()`` methods,
31
- or by using the ``Find.ToCursor()`` and ``Find.ToCursorAsync()`` methods.
30
+ You can retrieve a cursor by using the ``FindSync()`` and ``FindAsync()`` methods. You can
31
+ also convert the results of the ``Find()`` method to a cursor by chaining the ``ToCursor()``
32
+ or ``ToCursorAsync()`` method.
32
33
33
34
Sample Data
34
35
~~~~~~~~~~~
Original file line number Diff line number Diff line change
1
+ using System . Threading . Tasks ;
1
2
using MongoDB . Bson ;
2
3
using MongoDB . Bson . Serialization . Attributes ;
3
4
using MongoDB . Driver ;
@@ -7,7 +8,7 @@ public class Cursor
7
8
// Replace with your connection string
8
9
private const string MongoConnectionString = "<connection URI>" ;
9
10
10
- public static void Main ( string [ ] args )
11
+ public static async Task Main ( string [ ] args )
11
12
{
12
13
var mongoClient = new MongoClient ( MongoConnectionString ) ;
13
14
var database = mongoClient . GetDatabase ( "sample_restaurants" ) ;
@@ -127,7 +128,7 @@ public static void Main(string[] args)
127
128
128
129
using ( var cursor = await collection . FindAsync ( filter , options ) )
129
130
{
130
- while ( cursor . MoveNext ( ) )
131
+ while ( await cursor . MoveNext ( ) )
131
132
{
132
133
foreach ( var restaurant in cursor . Current )
133
134
{
You can’t perform that action at this time.
0 commit comments