diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index 19c599fe8c..bb21d49fbe 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -81,6 +81,9 @@ export class FindCursor extends AbstractCursor { // 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 @@ -114,10 +117,12 @@ 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; + } else { + this[kNumReturned] = this[kNumReturned] + (response?.cursor?.nextBatch?.length ?? 0); } return response; diff --git a/src/operations/find.ts b/src/operations/find.ts index 1c2ccdb1ca..cdf1a71176 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 ); } }