Skip to content

refactor(NODE-6146): put cursor response back under a flag #4098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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