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