1
+ import { type Connection } from '..' ;
1
2
import type { Document } from '../bson' ;
3
+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
2
4
import type { Collection } from '../collection' ;
3
- import type { Server } from '../sdam/server' ;
4
5
import type { ClientSession } from '../sessions' ;
5
- import { type TimeoutContext } from '../timeout' ;
6
- import { CommandOperation , type CommandOperationOptions } from './command' ;
6
+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
7
7
import { Aspect , defineAspects } from './operation' ;
8
8
9
9
/** @public */
@@ -17,7 +17,8 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
17
17
}
18
18
19
19
/** @internal */
20
- export class EstimatedDocumentCountOperation extends CommandOperation < number > {
20
+ export class EstimatedDocumentCountOperation extends ModernizedCommandOperation < number > {
21
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
21
22
override options : EstimatedDocumentCountOptions ;
22
23
collectionName : string ;
23
24
@@ -31,11 +32,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
31
32
return 'count' as const ;
32
33
}
33
34
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 {
39
36
const cmd : Document = { count : this . collectionName } ;
40
37
41
38
if ( typeof this . options . maxTimeMS === 'number' ) {
@@ -48,9 +45,11 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
48
45
cmd . comment = this . options . comment ;
49
46
}
50
47
51
- const response = await super . executeCommand ( server , session , cmd , timeoutContext ) ;
48
+ return cmd ;
49
+ }
52
50
53
- return response ?. n || 0 ;
51
+ override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : number {
52
+ return response . getNumber ( 'n' ) ?? 0 ;
54
53
}
55
54
}
56
55
0 commit comments