Skip to content

Commit cb4bb3c

Browse files
remove pre-3.6 logic
1 parent 176377a commit cb4bb3c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/cursor/find_cursor.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,29 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
7777

7878
const response = await executeOperation(this.client, findOperation);
7979

80-
// TODO: We only need this for legacy queries that do not support `limit`, maybe
81-
// the value should only be saved in those cases.
82-
if (response.cursor) {
83-
this[kNumReturned] = response.cursor.firstBatch.length;
84-
} else {
85-
this[kNumReturned] = response.documents ? response.documents.length : 0;
86-
}
80+
this[kNumReturned] = response.cursor.firstBatch.length;
8781

8882
// TODO: NODE-2882
8983
return { server: findOperation.server, session, response };
9084
}
9185

9286
/** @internal */
9387
override async getMore(batchSize: number): Promise<Document | null> {
94-
// NOTE: this is to support client provided limits in pre-command servers
9588
const numReturned = this[kNumReturned];
9689
if (numReturned) {
9790
const limit = this[kBuiltOptions].limit;
9891
batchSize =
9992
limit && limit > 0 && numReturned + batchSize > limit ? limit - numReturned : batchSize;
10093

10194
if (batchSize <= 0) {
95+
// this is an optimization for the special case of a limit for a find command to avoid an
96+
// extra getMore when the limit has been reached and the limit is a multiple of the batchSize.
97+
// This is a consequence of the new query engine in 5.0 having no knowledge of the limit as it
98+
// produces results for the find command. Once a batch is filled up, it is returned and only
99+
// on the subsequent getMore will the query framework consider the limit, determine the cursor
100+
// is exhausted and return a cursorId of zero.
101+
// instead, if we determine there are no more documents to request from the server, we preemptively
102+
// close the cursor
102103
await this.close().catch(() => null);
103104
return { cursor: { id: Long.ZERO, nextBatch: [] } };
104105
}

0 commit comments

Comments
 (0)