From 40fe57f28061766d6b6de8eb73d848971171a841 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 2 May 2024 11:47:07 -0400 Subject: [PATCH 1/3] refactor(NODE-6146): put cursor response back under a flag --- src/cursor/find_cursor.ts | 2 +- src/operations/find.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index 19c599fe8c1..ec1c26db195 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -114,7 +114,7 @@ export class FindCursor extends AbstractCursor { } } - 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; diff --git a/src/operations/find.ts b/src/operations/find.ts index 1c2ccdb1cac..cdf1a711767 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -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'; @@ -115,7 +114,7 @@ export class FindOperation extends CommandOperation { documentsReturnedIn: 'firstBatch', session }, - this.explain ? undefined : CursorResponse + undefined ); } } From 11dfa732fe2779576a87e46467d779f876b3f7a8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 2 May 2024 12:57:26 -0400 Subject: [PATCH 2/3] fix: 4.4 below --- src/cursor/find_cursor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index ec1c26db195..c93926ae636 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -81,6 +81,8 @@ export class FindCursor extends AbstractCursor { // the response is not a cursor when `explain` is enabled if (CursorResponse.is(response)) { this[kNumReturned] = response.batchSize; + } else { + this[kNumReturned] = this[kNumReturned] + (response?.cursor.firstBatch.length ?? 0); } // TODO: NODE-2882 @@ -118,6 +120,8 @@ export class FindCursor extends AbstractCursor { // 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; From 71f82f185e925c84ec7965d7a94c6e7e373bbce8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 2 May 2024 13:19:15 -0400 Subject: [PATCH 3/3] fix: explain --- src/cursor/find_cursor.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index c93926ae636..bb21d49fbed 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -82,7 +82,8 @@ export class FindCursor extends AbstractCursor { if (CursorResponse.is(response)) { this[kNumReturned] = response.batchSize; } else { - this[kNumReturned] = this[kNumReturned] + (response?.cursor.firstBatch.length ?? 0); + // Can be an explain response, hence the ?. on everything + this[kNumReturned] = this[kNumReturned] + (response?.cursor?.firstBatch?.length ?? 0); } // TODO: NODE-2882 @@ -121,7 +122,7 @@ export class FindCursor extends AbstractCursor { if (CursorResponse.is(response)) { this[kNumReturned] = this[kNumReturned] + response.batchSize; } else { - this[kNumReturned] = this[kNumReturned] + (response?.cursor.nextBatch.length ?? 0); + this[kNumReturned] = this[kNumReturned] + (response?.cursor?.nextBatch?.length ?? 0); } return response;