Skip to content

Commit bd062ec

Browse files
committed
At least one of the Primer examples should show how a cursor is used.
1 parent c25172e commit bd062ec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/MongoDB.Driver.Examples/QueryPrimer.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,23 @@ public async Task QueryAll()
3333
// @code: start
3434
var collection = _database.GetCollection<BsonDocument>("restaurants");
3535
var filter = new BsonDocument();
36-
var result = await collection.Find(filter).ToListAsync();
36+
var count = 0;
37+
using (var cursor = await collection.FindAsync(filter))
38+
{
39+
while (await cursor.MoveNextAsync())
40+
{
41+
var batch = cursor.Current;
42+
foreach (var document in batch)
43+
{
44+
// process document
45+
count++;
46+
}
47+
}
48+
}
3749
// @code: end
3850

3951
// @results: start
40-
result.Count().Should().Be(25359);
52+
count.Should().Be(25359);
4153
// @results: end
4254

4355
// @end: query-all

0 commit comments

Comments
 (0)