Skip to content

Commit ef2dee8

Browse files
update
1 parent 53792ae commit ef2dee8

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

src/collection.ts

Lines changed: 1 addition & 1 deletion
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

src/operations/update.ts

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
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, MongoInvalidArgumentError, MongoServerError } from '../error';
4-
import type { InferIdType, TODO_NODE_3286 } from '../mongo_types';
5-
import type { Server } from '../sdam/server';
6+
import type { InferIdType } from '../mongo_types';
67
import type { ClientSession } from '../sessions';
78
import { formatSort, type Sort, type SortForCmd } from '../sort';
8-
import { type TimeoutContext } from '../timeout';
99
import { hasAtomicOperators, type MongoDBNamespace } from '../utils';
10-
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
10+
import {
11+
type CollationOptions,
12+
type CommandOperationOptions,
13+
ModernizedCommandOperation
14+
} from './command';
1115
import { Aspect, defineAspects, type Hint } from './operation';
1216

1317
/** @public */
@@ -67,7 +71,8 @@ export interface UpdateStatement {
6771
* @internal
6872
* UpdateOperation is used in bulk write, while UpdateOneOperation and UpdateManyOperation are only used in the collections API
6973
*/
70-
export class UpdateOperation extends CommandOperation<Document> {
74+
export class UpdateOperation extends ModernizedCommandOperation<Document> {
75+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
7176
override options: UpdateOptions & { ordered?: boolean };
7277
statements: UpdateStatement[];
7378

@@ -95,12 +100,9 @@ export class UpdateOperation extends CommandOperation<Document> {
95100
return this.statements.every(op => op.multi == null || op.multi === false);
96101
}
97102

98-
override async execute(
99-
server: Server,
100-
session: ClientSession | undefined,
101-
timeoutContext: TimeoutContext
102-
): Promise<Document> {
103+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
103104
const options = this.options ?? {};
105+
104106
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
105107
const command: Document = {
106108
update: this.ns.collection,
@@ -130,8 +132,7 @@ export class UpdateOperation extends CommandOperation<Document> {
130132
}
131133
}
132134

133-
const res = await super.executeCommand(server, session, command, timeoutContext);
134-
return res;
135+
return command;
135136
}
136137
}
137138

@@ -149,12 +150,9 @@ export class UpdateOneOperation extends UpdateOperation {
149150
}
150151
}
151152

152-
override async execute(
153-
server: Server,
154-
session: ClientSession | undefined,
155-
timeoutContext: TimeoutContext
156-
): Promise<UpdateResult> {
157-
const res: TODO_NODE_3286 = await super.execute(server, session, timeoutContext);
153+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
154+
const res = super.handleOk(response);
155+
158156
if (this.explain != null) return res;
159157
if (res.code) throw new MongoServerError(res);
160158
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
@@ -184,12 +182,9 @@ export class UpdateManyOperation extends UpdateOperation {
184182
}
185183
}
186184

187-
override async execute(
188-
server: Server,
189-
session: ClientSession | undefined,
190-
timeoutContext: TimeoutContext
191-
): Promise<UpdateResult> {
192-
const res: TODO_NODE_3286 = await super.execute(server, session, timeoutContext);
185+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
186+
const res = super.handleOk(response);
187+
193188
if (this.explain != null) return res;
194189
if (res.code) throw new MongoServerError(res);
195190
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
@@ -240,13 +235,11 @@ export class ReplaceOneOperation extends UpdateOperation {
240235
}
241236
}
242237

243-
override async execute(
244-
server: Server,
245-
session: ClientSession | undefined,
246-
timeoutContext: TimeoutContext
247-
): Promise<UpdateResult> {
248-
const res: TODO_NODE_3286 = await super.execute(server, session, timeoutContext);
238+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
239+
const res = super.handleOk(response);
240+
249241
if (this.explain != null) return res;
242+
250243
if (res.code) throw new MongoServerError(res);
251244
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
252245

0 commit comments

Comments
 (0)