1+ import { type Connection } from '..' ;
12import type { Document } from '../bson' ;
3+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
24import type { Collection } from '../collection' ;
3- import type { Server } from '../sdam/server' ;
45import type { ClientSession } from '../sessions' ;
5- import { type TimeoutContext } from '../timeout' ;
6- import { CommandOperation , type CommandOperationOptions } from './command' ;
6+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
77import { Aspect , defineAspects } from './operation' ;
88
99/** @public */
@@ -17,7 +17,8 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
1717}
1818
1919/** @internal */
20- export class EstimatedDocumentCountOperation extends CommandOperation < number > {
20+ export class EstimatedDocumentCountOperation extends ModernizedCommandOperation < number > {
21+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
2122 override options : EstimatedDocumentCountOptions ;
2223 collectionName : string ;
2324
@@ -31,11 +32,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
3132 return 'count' as const ;
3233 }
3334
34- override async execute (
35- server : Server ,
36- session : ClientSession | undefined ,
37- timeoutContext : TimeoutContext
38- ) : Promise < number > {
35+ override buildCommandDocument ( _connection : Connection , _session ?: ClientSession ) : Document {
3936 const cmd : Document = { count : this . collectionName } ;
4037
4138 if ( typeof this . options . maxTimeMS === 'number' ) {
@@ -48,9 +45,11 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
4845 cmd . comment = this . options . comment ;
4946 }
5047
51- const response = await super . executeCommand ( server , session , cmd , timeoutContext ) ;
48+ return cmd ;
49+ }
5250
53- return response ?. n || 0 ;
51+ override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : number {
52+ return response . getNumber ( 'n' ) ?? 0 ;
5453 }
5554}
5655
0 commit comments