diff --git a/src/change_stream.ts b/src/change_stream.ts index b260b4d80a..aab273b06c 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -489,15 +489,11 @@ export class ChangeStreamCursor extends Abs } _initialize(session: ClientSession, callback: Callback): void { - const aggregateOperation = new AggregateOperation( - { s: { namespace: this.namespace } }, - this.pipeline, - { - ...this.cursorOptions, - ...this.options, - session - } - ); + const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, { + ...this.cursorOptions, + ...this.options, + session + }); executeOperation(this.topology, aggregateOperation, (err, response) => { if (err || response == null) { diff --git a/src/collection.ts b/src/collection.ts index f9ec68a439..f7d1840c3b 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -1387,7 +1387,6 @@ export class Collection { } return new AggregationCursor( - this as TODO_NODE_3286, getTopology(this), this.s.namespace, pipeline, diff --git a/src/cursor/aggregation_cursor.ts b/src/cursor/aggregation_cursor.ts index 12f50c3155..5b1e3fa119 100644 --- a/src/cursor/aggregation_cursor.ts +++ b/src/cursor/aggregation_cursor.ts @@ -7,7 +7,6 @@ import type { Sort } from '../sort'; import type { Topology } from '../sdam/topology'; import type { Callback, MongoDBNamespace } from '../utils'; import type { ClientSession } from '../sessions'; -import type { OperationParent } from '../operations/command'; import type { AbstractCursorOptions } from './abstract_cursor'; import type { ExplainVerbosityLike } from '../explain'; import type { Projection } from '../mongo_types'; @@ -15,8 +14,6 @@ import type { Projection } from '../mongo_types'; /** @public */ export interface AggregationCursorOptions extends AbstractCursorOptions, AggregateOptions {} -/** @internal */ -const kParent = Symbol('parent'); /** @internal */ const kPipeline = Symbol('pipeline'); /** @internal */ @@ -30,8 +27,6 @@ const kOptions = Symbol('options'); * @public */ export class AggregationCursor extends AbstractCursor { - /** @internal */ - [kParent]: OperationParent; // TODO: NODE-2883 /** @internal */ [kPipeline]: Document[]; /** @internal */ @@ -39,7 +34,6 @@ export class AggregationCursor extends AbstractCursor extends AbstractCursor extends AbstractCursor { const clonedOptions = mergeOptions({}, this[kOptions]); delete clonedOptions.session; - return new AggregationCursor(this[kParent], this.topology, this.namespace, this[kPipeline], { + return new AggregationCursor(this.topology, this.namespace, this[kPipeline], { ...clonedOptions }); } @@ -70,7 +63,7 @@ export class AggregationCursor extends AbstractCursor): void { - const aggregateOperation = new AggregateOperation(this[kParent], this[kPipeline], { + const aggregateOperation = new AggregateOperation(this.namespace, this[kPipeline], { ...this[kOptions], ...this.cursorOptions, session @@ -97,7 +90,7 @@ export class AggregationCursor extends AbstractCursor extends CommandOperation { pipeline: Document[]; hasWriteStage: boolean; - constructor(parent: OperationParent, pipeline: Document[], options?: AggregateOptions) { - super(parent, options); + constructor(ns: MongoDBNamespace, pipeline: Document[], options?: AggregateOptions) { + super(undefined, { ...options, dbName: ns.db }); this.options = options ?? {}; - this.target = - parent.s.namespace && parent.s.namespace.collection - ? parent.s.namespace.collection - : DB_AGGREGATE_COLLECTION; + + // Covers when ns.collection is null, undefined or the empty string, use DB_AGGREGATE_COLLECTION + this.target = ns.collection || DB_AGGREGATE_COLLECTION; this.pipeline = pipeline; diff --git a/src/operations/count_documents.ts b/src/operations/count_documents.ts index d3bce65fbc..27b65ec3db 100644 --- a/src/operations/count_documents.ts +++ b/src/operations/count_documents.ts @@ -29,7 +29,7 @@ export class CountDocumentsOperation extends AggregateOperation { pipeline.push({ $group: { _id: 1, n: { $sum: 1 } } }); - super(collection, pipeline, options); + super(collection.s.namespace, pipeline, options); } execute(server: Server, session: ClientSession, callback: Callback): void {