Skip to content

Commit

Permalink
refactor(NODE-6146): put cursor response back under a flag (#4098)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored May 2, 2024
1 parent 9d73f45 commit cc4c874
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/cursor/find_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
// the response is not a cursor when `explain` is enabled
if (CursorResponse.is(response)) {
this[kNumReturned] = response.batchSize;
} else {
// Can be an explain response, hence the ?. on everything
this[kNumReturned] = this[kNumReturned] + (response?.cursor?.firstBatch?.length ?? 0);
}

// TODO: NODE-2882
Expand Down Expand Up @@ -114,10 +117,12 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
}
}

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

return response;
Expand Down
3 changes: 1 addition & 2 deletions src/operations/find.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Document } from '../bson';
import { CursorResponse } from '../cmap/wire_protocol/responses';
import { MongoInvalidArgumentError } from '../error';
import { ReadConcern } from '../read_concern';
import type { Server } from '../sdam/server';
Expand Down Expand Up @@ -115,7 +114,7 @@ export class FindOperation extends CommandOperation<Document> {
documentsReturnedIn: 'firstBatch',
session
},
this.explain ? undefined : CursorResponse
undefined
);
}
}
Expand Down

0 comments on commit cc4c874

Please sign in to comment.