Skip to content

Commit 82e6c70

Browse files
committed
CSHARP-822: added in check to not fetch the next batch when it is not required.
1 parent 513b181 commit 82e6c70

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

MongoDB.Driver/Operations/QueryOperation.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,27 @@ public IEnumerator<TDocument> Execute(IConnectionProvider connectionProvider)
8383
reply = GetFirstBatch(connectionProvider);
8484
foreach (var document in reply.Documents)
8585
{
86+
yield return document;
87+
count++;
88+
8689
if (limit != 0 && count == limit)
8790
{
8891
yield break;
8992
}
90-
yield return document;
91-
count++;
9293
}
9394

9495
while (reply.CursorId != 0)
9596
{
9697
reply = GetNextBatch(connectionProvider, reply.CursorId);
9798
foreach (var document in reply.Documents)
9899
{
100+
yield return document;
101+
count++;
102+
99103
if (limit != 0 && count == limit)
100104
{
101105
yield break;
102106
}
103-
yield return document;
104-
count++;
105107
}
106108

107109
if (reply.CursorId != 0 && (_flags & QueryFlags.TailableCursor) != 0)

0 commit comments

Comments
 (0)