Skip to content

Commit 0b9e3d1

Browse files
count
1 parent e628296 commit 0b9e3d1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/operations/count.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { type Connection } from '..';
12
import type { Document } from '../bson';
3+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
24
import type { Collection } from '../collection';
3-
import type { Server } from '../sdam/server';
45
import type { ClientSession } from '../sessions';
5-
import { type TimeoutContext } from '../timeout';
66
import type { MongoDBNamespace } from '../utils';
7-
import { CommandOperation, type CommandOperationOptions } from './command';
7+
import { type CommandOperationOptions, ModernizedCommandOperation } from './command';
88
import { Aspect, defineAspects } from './operation';
99

1010
/** @public */
@@ -22,7 +22,8 @@ export interface CountOptions extends CommandOperationOptions {
2222
}
2323

2424
/** @internal */
25-
export class CountOperation extends CommandOperation<number> {
25+
export class CountOperation extends ModernizedCommandOperation<number> {
26+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
2627
override options: CountOptions;
2728
collectionName?: string;
2829
query: Document;
@@ -39,11 +40,7 @@ export class CountOperation extends CommandOperation<number> {
3940
return 'count' as const;
4041
}
4142

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 {
4744
const options = this.options;
4845
const cmd: Document = {
4946
count: this.collectionName,
@@ -66,8 +63,11 @@ export class CountOperation extends CommandOperation<number> {
6663
cmd.maxTimeMS = options.maxTimeMS;
6764
}
6865

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;
7171
}
7272
}
7373

0 commit comments

Comments
 (0)