Skip to content

Commit 0ed7528

Browse files
delete
1 parent 0651c7f commit 0ed7528

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

src/collection.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export class Collection<TSchema extends Document = Document> {
430430
filter,
431431
replacement,
432432
resolveOptions(this, options)
433-
)
433+
) as TODO_NODE_3286
434434
);
435435
}
436436

@@ -473,7 +473,11 @@ export class Collection<TSchema extends Document = Document> {
473473
): Promise<DeleteResult> {
474474
return await executeOperation(
475475
this.client,
476-
new DeleteOneOperation(this as TODO_NODE_3286, filter, resolveOptions(this, options))
476+
new DeleteOneOperation(
477+
this as TODO_NODE_3286,
478+
filter,
479+
resolveOptions(this, options)
480+
) as TODO_NODE_3286
477481
);
478482
}
479483

@@ -489,7 +493,11 @@ export class Collection<TSchema extends Document = Document> {
489493
): Promise<DeleteResult> {
490494
return await executeOperation(
491495
this.client,
492-
new DeleteManyOperation(this as TODO_NODE_3286, filter, resolveOptions(this, options))
496+
new DeleteManyOperation(
497+
this as TODO_NODE_3286,
498+
filter,
499+
resolveOptions(this, options)
500+
) as TODO_NODE_3286
493501
);
494502
}
495503

src/operations/delete.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { Document } from '../bson';
2+
import { type Connection } from '../cmap/connection';
3+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
24
import type { Collection } from '../collection';
35
import { MongoCompatibilityError, MongoServerError } from '../error';
46
import { type TODO_NODE_3286 } from '../mongo_types';
@@ -7,7 +9,11 @@ import type { ClientSession } from '../sessions';
79
import { type TimeoutContext } from '../timeout';
810
import { type MongoDBNamespace } from '../utils';
911
import { type WriteConcernOptions } from '../write_concern';
10-
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
12+
import {
13+
type CollationOptions,
14+
type CommandOperationOptions,
15+
ModernizedCommandOperation
16+
} from './command';
1117
import { Aspect, defineAspects, type Hint } from './operation';
1218

1319
/** @public */
@@ -43,7 +49,8 @@ export interface DeleteStatement {
4349
}
4450

4551
/** @internal */
46-
export class DeleteOperation extends CommandOperation<DeleteResult> {
52+
export class DeleteOperation extends ModernizedCommandOperation<Document> {
53+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
4754
override options: DeleteOptions;
4855
statements: DeleteStatement[];
4956

@@ -66,12 +73,9 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
6673
return this.statements.every(op => (op.limit != null ? op.limit > 0 : true));
6774
}
6875

69-
override async execute(
70-
server: Server,
71-
session: ClientSession | undefined,
72-
timeoutContext: TimeoutContext
73-
): Promise<DeleteResult> {
74-
const options = this.options ?? {};
76+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
77+
const options = this.options;
78+
7579
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
7680
const command: Document = {
7781
delete: this.ns.collection,
@@ -97,13 +101,7 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
97101
}
98102
}
99103

100-
const res: TODO_NODE_3286 = await super.executeCommand(
101-
server,
102-
session,
103-
command,
104-
timeoutContext
105-
);
106-
return res;
104+
return command;
107105
}
108106
}
109107

@@ -112,13 +110,14 @@ export class DeleteOneOperation extends DeleteOperation {
112110
super(collection.s.namespace, [makeDeleteStatement(filter, { ...options, limit: 1 })], options);
113111
}
114112

115-
override async execute(
116-
server: Server,
117-
session: ClientSession | undefined,
118-
timeoutContext: TimeoutContext
119-
): Promise<DeleteResult> {
120-
const res: TODO_NODE_3286 = await super.execute(server, session, timeoutContext);
113+
override handleOk(
114+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
115+
): DeleteResult {
116+
const res = super.handleOk(response);
117+
118+
// @ts-expect-error Explain commands have broken TS
121119
if (this.explain) return res;
120+
122121
if (res.code) throw new MongoServerError(res);
123122
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
124123

@@ -133,13 +132,14 @@ export class DeleteManyOperation extends DeleteOperation {
133132
super(collection.s.namespace, [makeDeleteStatement(filter, options)], options);
134133
}
135134

136-
override async execute(
137-
server: Server,
138-
session: ClientSession | undefined,
139-
timeoutContext: TimeoutContext
140-
): Promise<DeleteResult> {
141-
const res: TODO_NODE_3286 = await super.execute(server, session, timeoutContext);
135+
override handleOk(
136+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
137+
): DeleteResult {
138+
const res = super.handleOk(response);
139+
140+
// @ts-expect-error Explain commands have broken TS
142141
if (this.explain) return res;
142+
143143
if (res.code) throw new MongoServerError(res);
144144
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
145145

0 commit comments

Comments
 (0)