1
1
import type { Document } from '../bson' ;
2
+ import { type Connection } from '../cmap/connection' ;
3
+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
2
4
import type { Collection } from '../collection' ;
3
5
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' ;
6
7
import type { ClientSession } from '../sessions' ;
7
8
import { formatSort , type Sort , type SortForCmd } from '../sort' ;
8
- import { type TimeoutContext } from '../timeout' ;
9
9
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' ;
11
15
import { Aspect , defineAspects , type Hint } from './operation' ;
12
16
13
17
/** @public */
@@ -67,7 +71,8 @@ export interface UpdateStatement {
67
71
* @internal
68
72
* UpdateOperation is used in bulk write, while UpdateOneOperation and UpdateManyOperation are only used in the collections API
69
73
*/
70
- export class UpdateOperation extends CommandOperation < Document > {
74
+ export class UpdateOperation extends ModernizedCommandOperation < Document > {
75
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
71
76
override options : UpdateOptions & { ordered ?: boolean } ;
72
77
statements : UpdateStatement [ ] ;
73
78
@@ -95,12 +100,9 @@ export class UpdateOperation extends CommandOperation<Document> {
95
100
return this . statements . every ( op => op . multi == null || op . multi === false ) ;
96
101
}
97
102
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 {
103
104
const options = this . options ?? { } ;
105
+
104
106
const ordered = typeof options . ordered === 'boolean' ? options . ordered : true ;
105
107
const command : Document = {
106
108
update : this . ns . collection ,
@@ -130,8 +132,7 @@ export class UpdateOperation extends CommandOperation<Document> {
130
132
}
131
133
}
132
134
133
- const res = await super . executeCommand ( server , session , command , timeoutContext ) ;
134
- return res ;
135
+ return command ;
135
136
}
136
137
}
137
138
@@ -149,12 +150,9 @@ export class UpdateOneOperation extends UpdateOperation {
149
150
}
150
151
}
151
152
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
+
158
156
if ( this . explain != null ) return res ;
159
157
if ( res . code ) throw new MongoServerError ( res ) ;
160
158
if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
@@ -184,12 +182,9 @@ export class UpdateManyOperation extends UpdateOperation {
184
182
}
185
183
}
186
184
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
+
193
188
if ( this . explain != null ) return res ;
194
189
if ( res . code ) throw new MongoServerError ( res ) ;
195
190
if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
@@ -240,13 +235,11 @@ export class ReplaceOneOperation extends UpdateOperation {
240
235
}
241
236
}
242
237
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
+
249
241
if ( this . explain != null ) return res ;
242
+
250
243
if ( res . code ) throw new MongoServerError ( res ) ;
251
244
if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
252
245
0 commit comments