1+ import { type Connection } from '..' ;
12import type { Document } from '../bson' ;
23import { CursorResponse , ExplainedCursorResponse } from '../cmap/wire_protocol/responses' ;
34import { type CursorTimeoutMode } from '../cursor/abstract_cursor' ;
45import { MongoInvalidArgumentError } from '../error' ;
56import { type ExplainOptions } from '../explain' ;
6- import type { Server } from '../sdam/server' ;
7- import type { ClientSession } from '../sessions' ;
8- import { type TimeoutContext } from '../timeout' ;
97import { maxWireVersion , type MongoDBNamespace } from '../utils' ;
108import { WriteConcern } from '../write_concern' ;
11- import { type CollationOptions , CommandOperation , type CommandOperationOptions } from './command' ;
9+ import {
10+ type CollationOptions ,
11+ type CommandOperationOptions ,
12+ ModernizedCommandOperation
13+ } from './command' ;
1214import { Aspect , defineAspects , type Hint } from './operation' ;
1315
1416/** @internal */
@@ -51,7 +53,8 @@ export interface AggregateOptions extends Omit<CommandOperationOptions, 'explain
5153}
5254
5355/** @internal */
54- export class AggregateOperation extends CommandOperation < CursorResponse > {
56+ export class AggregateOperation extends ModernizedCommandOperation < CursorResponse > {
57+ override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse ;
5558 override options : AggregateOptions ;
5659 target : string | typeof DB_AGGREGATE_COLLECTION ;
5760 pipeline : Document [ ] ;
@@ -79,9 +82,7 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
7982 }
8083 }
8184
82- if ( this . hasWriteStage ) {
83- this . trySecondaryWrite = true ;
84- } else {
85+ if ( ! this . hasWriteStage ) {
8586 delete this . options . writeConcern ;
8687 }
8788
@@ -94,6 +95,8 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
9495 if ( options ?. cursor != null && typeof options . cursor !== 'object' ) {
9596 throw new MongoInvalidArgumentError ( 'Cursor options must be an object' ) ;
9697 }
98+
99+ this . SERVER_COMMAND_RESPONSE_TYPE = this . explain ? ExplainedCursorResponse : CursorResponse ;
97100 }
98101
99102 override get commandName ( ) {
@@ -108,13 +111,9 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
108111 this . pipeline . push ( stage ) ;
109112 }
110113
111- override async execute (
112- server : Server ,
113- session : ClientSession | undefined ,
114- timeoutContext : TimeoutContext
115- ) : Promise < CursorResponse > {
116- const options : AggregateOptions = this . options ;
117- const serverWireVersion = maxWireVersion ( server ) ;
114+ override buildCommandDocument ( connection : Connection ) : Document {
115+ const options = this . options ;
116+ const serverWireVersion = maxWireVersion ( connection ) ;
118117 const command : Document = { aggregate : this . target , pipeline : this . pipeline } ;
119118
120119 if ( this . hasWriteStage && serverWireVersion < MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT ) {
@@ -152,13 +151,13 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
152151 command . cursor . batchSize = options . batchSize ;
153152 }
154153
155- return await super . executeCommand (
156- server ,
157- session ,
158- command ,
159- timeoutContext ,
160- this . explain ? ExplainedCursorResponse : CursorResponse
161- ) ;
154+ return command ;
155+ }
156+
157+ override handleOk (
158+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
159+ ) : CursorResponse {
160+ return response ;
162161 }
163162}
164163
0 commit comments