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
6
import type { MongoDBNamespace } from '../utils' ;
7
- import { CommandOperation , type CommandOperationOptions } from './command' ;
7
+ import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
8
8
import { Aspect , defineAspects } from './operation' ;
9
9
10
10
/** @public */
@@ -22,7 +22,8 @@ export interface CountOptions extends CommandOperationOptions {
22
22
}
23
23
24
24
/** @internal */
25
- export class CountOperation extends CommandOperation < number > {
25
+ export class CountOperation extends ModernizedCommandOperation < number > {
26
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
26
27
override options : CountOptions ;
27
28
collectionName ?: string ;
28
29
query : Document ;
@@ -39,11 +40,7 @@ export class CountOperation extends CommandOperation<number> {
39
40
return 'count' as const ;
40
41
}
41
42
42
- override async execute (
43
- server : Server ,
44
- session : ClientSession | undefined ,
45
- timeoutContext : TimeoutContext
46
- ) : Promise < number > {
43
+ override buildCommandDocument ( _connection : Connection , _session ?: ClientSession ) : Document {
47
44
const options = this . options ;
48
45
const cmd : Document = {
49
46
count : this . collectionName ,
@@ -66,8 +63,11 @@ export class CountOperation extends CommandOperation<number> {
66
63
cmd . maxTimeMS = options . maxTimeMS ;
67
64
}
68
65
69
- const result = await super . executeCommand ( server , session , cmd , timeoutContext ) ;
70
- return result ? result . n : 0 ;
66
+ return cmd ;
67
+ }
68
+
69
+ override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : number {
70
+ return response . getNumber ( 'n' ) ?? 0 ;
71
71
}
72
72
}
73
73
0 commit comments