Skip to content

Commit

Permalink
fix: old servers
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Apr 18, 2024
1 parent 7ec39bc commit a537db1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/cmap/wire_protocol/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ export class CursorResponse extends MongoDBResponse {
public id: Long | null = null;
public ns: MongoDBNamespace | null = null;
public documents: any | null = null;
public batchSize = 0;

private batch: OnDemandDocument | null = null;
private values: Generator<OnDemandDocument, void, void> | null = null;
private batchSize = 0;
private iterated = 0;

constructor(b: Uint8Array, o?: number, a?: boolean) {
Expand Down Expand Up @@ -184,7 +184,7 @@ export class CursorResponse extends MongoDBResponse {
});
}

static isCursorResponse(value: unknown): value is CursorResponse {
static override is(value: unknown): value is CursorResponse {
return value instanceof CursorResponse;
}
}
4 changes: 2 additions & 2 deletions src/cursor/abstract_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export abstract class AbstractCursor<
const state = await this._initialize(this[kSession]);
const response = state.response;
this[kServer] = state.server;
if (CursorResponse.isCursorResponse(response)) {
if (CursorResponse.is(response)) {
this[kId] = response.id;
if (response.ns) this[kNamespace] = response.ns;
this[kDocuments] = response.documents;
Expand Down Expand Up @@ -798,7 +798,7 @@ async function next<T>(

try {
const response = await cursor.getMore(batchSize);
if (CursorResponse.isCursorResponse(response)) {
if (CursorResponse.is(response)) {
cursor[kId] = response.id;
cursor[kDocuments] = response.documents;
} else if (response) {
Expand Down
11 changes: 7 additions & 4 deletions src/cursor/find_cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Document, Long } from '../bson';
import { CursorResponse } from '../cmap/wire_protocol/responses';
import { MongoInvalidArgumentError, MongoTailableCursorError } from '../error';
import { type ExplainVerbosityLike } from '../explain';
import type { MongoClient } from '../mongo_client';
Expand Down Expand Up @@ -34,7 +35,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
/** @internal */
[kFilter]: Document;
/** @internal */
[kNumReturned]?: number;
[kNumReturned] = 0;
/** @internal */
[kBuiltOptions]: FindOptions;

Expand Down Expand Up @@ -78,7 +79,9 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
const response = await executeOperation(this.client, findOperation);

// the response is not a cursor when `explain` is enabled
this[kNumReturned] = response.cursor?.firstBatch?.length;
if (CursorResponse.is(response)) {
this[kNumReturned] = response.batchSize;
}

// TODO: NODE-2882
return { server: findOperation.server, session, response };
Expand Down Expand Up @@ -113,8 +116,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {

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

return response;
Expand Down

0 comments on commit a537db1

Please sign in to comment.