|
1 | 1 | import { type Document, Long } from '../bson';
|
| 2 | +import { CursorResponse } from '../cmap/wire_protocol/responses'; |
2 | 3 | import { MongoInvalidArgumentError, MongoTailableCursorError } from '../error';
|
3 | 4 | import { type ExplainVerbosityLike } from '../explain';
|
4 | 5 | import type { MongoClient } from '../mongo_client';
|
@@ -34,7 +35,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
34 | 35 | /** @internal */
|
35 | 36 | [kFilter]: Document;
|
36 | 37 | /** @internal */
|
37 |
| - [kNumReturned]?: number; |
| 38 | + [kNumReturned] = 0; |
38 | 39 | /** @internal */
|
39 | 40 | [kBuiltOptions]: FindOptions;
|
40 | 41 |
|
@@ -78,7 +79,9 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
78 | 79 | const response = await executeOperation(this.client, findOperation);
|
79 | 80 |
|
80 | 81 | // the response is not a cursor when `explain` is enabled
|
81 |
| - this[kNumReturned] = response.cursor?.firstBatch?.length; |
| 82 | + if (CursorResponse.is(response)) { |
| 83 | + this[kNumReturned] = response.batchSize; |
| 84 | + } |
82 | 85 |
|
83 | 86 | // TODO: NODE-2882
|
84 | 87 | return { server: findOperation.server, session, response };
|
@@ -113,8 +116,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
113 | 116 |
|
114 | 117 | const response = await super.getMore(batchSize, true);
|
115 | 118 | // TODO: wrap this in some logic to prevent it from happening if we don't need this support
|
116 |
| - if (response) { |
117 |
| - this[kNumReturned] = this[kNumReturned] + response.batchLength; |
| 119 | + if (CursorResponse.is(response)) { |
| 120 | + this[kNumReturned] = this[kNumReturned] + response.batchSize; |
118 | 121 | }
|
119 | 122 |
|
120 | 123 | return response;
|
|
0 commit comments