11import type { Document } from '../bson' ;
22import { type Connection } from '../cmap/connection' ;
3- import { CursorResponse } from '../cmap/wire_protocol/responses' ;
3+ import { CursorResponse , MongoDBResponse } from '../cmap/wire_protocol/responses' ;
44import type { Collection } from '../collection' ;
55import { type AbstractCursorOptions } from '../cursor/abstract_cursor' ;
66import { MongoCompatibilityError } from '../error' ;
77import { type OneOrMore } from '../mongo_types' ;
8- import type { Server } from '../sdam/server' ;
9- import type { ClientSession } from '../sessions' ;
10- import { type TimeoutContext } from '../timeout' ;
118import { isObject , maxWireVersion , type MongoDBNamespace } from '../utils' ;
129import {
1310 type CollationOptions ,
14- CommandOperation ,
1511 type CommandOperationOptions ,
1612 ModernizedCommandOperation ,
1713 type OperationParent
@@ -246,7 +242,8 @@ type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
246242} ;
247243
248244/** @internal */
249- export class CreateIndexesOperation extends CommandOperation < string [ ] > {
245+ export class CreateIndexesOperation extends ModernizedCommandOperation < string [ ] > {
246+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
250247 override options : CreateIndexesOptions ;
251248 collectionName : string ;
252249 indexes : ReadonlyArray < ResolvedIndexDescription > ;
@@ -260,6 +257,8 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
260257 super ( parent , options ) ;
261258
262259 this . options = options ?? { } ;
260+ // collation is set on each index, it should not be defined at the root
261+ this . options . collation = undefined ;
263262 this . collectionName = collectionName ;
264263 this . indexes = indexes . map ( ( userIndex : IndexDescription ) : ResolvedIndexDescription => {
265264 // Ensure the key is a Map to preserve index key ordering
@@ -273,6 +272,7 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
273272 key
274273 } ;
275274 } ) ;
275+ this . ns = parent . s . namespace ;
276276 }
277277
278278 static fromIndexDescriptionArray (
@@ -299,15 +299,11 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
299299 return 'createIndexes' ;
300300 }
301301
302- override async execute (
303- server : Server ,
304- session : ClientSession | undefined ,
305- timeoutContext : TimeoutContext
306- ) : Promise < string [ ] > {
302+ override buildCommandDocument ( connection : Connection ) : Document {
307303 const options = this . options ;
308304 const indexes = this . indexes ;
309305
310- const serverWireVersion = maxWireVersion ( server ) ;
306+ const serverWireVersion = maxWireVersion ( connection ) ;
311307
312308 const cmd : Document = { createIndexes : this . collectionName , indexes } ;
313309
@@ -319,13 +315,11 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
319315 }
320316 cmd . commitQuorum = options . commitQuorum ;
321317 }
318+ return cmd ;
319+ }
322320
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 || '' ) ;
329323 return indexNames ;
330324 }
331325}
@@ -334,7 +328,8 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
334328export type DropIndexesOptions = CommandOperationOptions ;
335329
336330/** @internal */
337- export class DropIndexOperation extends CommandOperation < Document > {
331+ export class DropIndexOperation extends ModernizedCommandOperation < Document > {
332+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
338333 override options : DropIndexesOptions ;
339334 collection : Collection ;
340335 indexName : string ;
@@ -345,19 +340,15 @@ export class DropIndexOperation extends CommandOperation<Document> {
345340 this . options = options ?? { } ;
346341 this . collection = collection ;
347342 this . indexName = indexName ;
343+ this . ns = collection . fullNamespace ;
348344 }
349345
350346 override get commandName ( ) {
351347 return 'dropIndexes' as const ;
352348 }
353349
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 } ;
361352 }
362353}
363354
0 commit comments