Skip to content

Commit cc4c874

Browse files
authored
refactor(NODE-6146): put cursor response back under a flag (#4098)
1 parent 9d73f45 commit cc4c874

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/cursor/find_cursor.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
8181
// the response is not a cursor when `explain` is enabled
8282
if (CursorResponse.is(response)) {
8383
this[kNumReturned] = response.batchSize;
84+
} else {
85+
// Can be an explain response, hence the ?. on everything
86+
this[kNumReturned] = this[kNumReturned] + (response?.cursor?.firstBatch?.length ?? 0);
8487
}
8588

8689
// TODO: NODE-2882
@@ -114,10 +117,12 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
114117
}
115118
}
116119

117-
const response = await super.getMore(batchSize, this.client.autoEncrypter ? false : true);
120+
const response = await super.getMore(batchSize, false);
118121
// TODO: wrap this in some logic to prevent it from happening if we don't need this support
119122
if (CursorResponse.is(response)) {
120123
this[kNumReturned] = this[kNumReturned] + response.batchSize;
124+
} else {
125+
this[kNumReturned] = this[kNumReturned] + (response?.cursor?.nextBatch?.length ?? 0);
121126
}
122127

123128
return response;

src/operations/find.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Document } from '../bson';
2-
import { CursorResponse } from '../cmap/wire_protocol/responses';
32
import { MongoInvalidArgumentError } from '../error';
43
import { ReadConcern } from '../read_concern';
54
import type { Server } from '../sdam/server';
@@ -115,7 +114,7 @@ export class FindOperation extends CommandOperation<Document> {
115114
documentsReturnedIn: 'firstBatch',
116115
session
117116
},
118-
this.explain ? undefined : CursorResponse
117+
undefined
119118
);
120119
}
121120
}

0 commit comments

Comments
 (0)