1
1
import type { Document } from '../bson' ;
2
- import { CursorResponse } from '../cmap/wire_protocol/responses' ;
2
+ import { type Connection } from '../cmap/connection' ;
3
+ import { CursorResponse , MongoDBResponse } from '../cmap/wire_protocol/responses' ;
3
4
import type { Collection } from '../collection' ;
4
5
import { type AbstractCursorOptions } from '../cursor/abstract_cursor' ;
5
6
import { MongoCompatibilityError } from '../error' ;
@@ -12,6 +13,7 @@ import {
12
13
type CollationOptions ,
13
14
CommandOperation ,
14
15
type CommandOperationOptions ,
16
+ ModernizedCommandOperation ,
15
17
type OperationParent
16
18
} from './command' ;
17
19
import { Aspect , defineAspects } from './operation' ;
@@ -244,7 +246,8 @@ type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
244
246
} ;
245
247
246
248
/** @internal */
247
- export class CreateIndexesOperation extends CommandOperation < string [ ] > {
249
+ export class CreateIndexesOperation extends ModernizedCommandOperation < string [ ] > {
250
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
248
251
override options : CreateIndexesOptions ;
249
252
collectionName : string ;
250
253
indexes : ReadonlyArray < ResolvedIndexDescription > ;
@@ -258,6 +261,8 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
258
261
super ( parent , options ) ;
259
262
260
263
this . options = options ?? { } ;
264
+ // collation is set on each index, it should not be defined at the root
265
+ this . options . collation = undefined ;
261
266
this . collectionName = collectionName ;
262
267
this . indexes = indexes . map ( ( userIndex : IndexDescription ) : ResolvedIndexDescription => {
263
268
// Ensure the key is a Map to preserve index key ordering
@@ -271,6 +276,7 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
271
276
key
272
277
} ;
273
278
} ) ;
279
+ this . ns = parent . s . namespace ;
274
280
}
275
281
276
282
static fromIndexDescriptionArray (
@@ -297,15 +303,11 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
297
303
return 'createIndexes' ;
298
304
}
299
305
300
- override async execute (
301
- server : Server ,
302
- session : ClientSession | undefined ,
303
- timeoutContext : TimeoutContext
304
- ) : Promise < string [ ] > {
306
+ override buildCommandDocument ( connection : Connection ) : Document {
305
307
const options = this . options ;
306
308
const indexes = this . indexes ;
307
309
308
- const serverWireVersion = maxWireVersion ( server ) ;
310
+ const serverWireVersion = maxWireVersion ( connection ) ;
309
311
310
312
const cmd : Document = { createIndexes : this . collectionName , indexes } ;
311
313
@@ -317,13 +319,11 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
317
319
}
318
320
cmd . commitQuorum = options . commitQuorum ;
319
321
}
322
+ return cmd ;
323
+ }
320
324
321
- // collation is set on each index, it should not be defined at the root
322
- this . options . collation = undefined ;
323
-
324
- await super . executeCommand ( server , session , cmd , timeoutContext ) ;
325
-
326
- const indexNames = indexes . map ( index => index . name || '' ) ;
325
+ override handleOk ( _response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : string [ ] {
326
+ const indexNames = this . indexes . map ( index => index . name || '' ) ;
327
327
return indexNames ;
328
328
}
329
329
}
@@ -332,7 +332,8 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
332
332
export type DropIndexesOptions = CommandOperationOptions ;
333
333
334
334
/** @internal */
335
- export class DropIndexOperation extends CommandOperation < Document > {
335
+ export class DropIndexOperation extends ModernizedCommandOperation < Document > {
336
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
336
337
override options : DropIndexesOptions ;
337
338
collection : Collection ;
338
339
indexName : string ;
@@ -343,19 +344,15 @@ export class DropIndexOperation extends CommandOperation<Document> {
343
344
this . options = options ?? { } ;
344
345
this . collection = collection ;
345
346
this . indexName = indexName ;
347
+ this . ns = collection . fullNamespace ;
346
348
}
347
349
348
350
override get commandName ( ) {
349
351
return 'dropIndexes' as const ;
350
352
}
351
353
352
- override async execute (
353
- server : Server ,
354
- session : ClientSession | undefined ,
355
- timeoutContext : TimeoutContext
356
- ) : Promise < Document > {
357
- const cmd = { dropIndexes : this . collection . collectionName , index : this . indexName } ;
358
- return await super . executeCommand ( server , session , cmd , timeoutContext ) ;
354
+ override buildCommandDocument ( _connection : Connection ) : Document {
355
+ return { dropIndexes : this . collection . collectionName , index : this . indexName } ;
359
356
}
360
357
}
361
358
0 commit comments