@@ -2386,21 +2386,19 @@ export default class Collection extends ShellApiWithMongoClass {
23862386 }
23872387
23882388 async createSearchIndex (
2389- name ? : string ,
2390- definition ? : SearchIndexDefinition
2389+ name : string ,
2390+ definition : SearchIndexDefinition
23912391 ) : Promise < string > ;
23922392 async createSearchIndex (
2393- name ? : string ,
2394- type ? : 'search' | 'vectorSearch' ,
2395- definition ? : SearchIndexDefinition
2393+ name : string ,
2394+ type : 'search' | 'vectorSearch' ,
2395+ definition : SearchIndexDefinition
23962396 ) : Promise < string > ;
23972397 async createSearchIndex (
2398- definition ? : SearchIndexDefinition ,
2398+ definition : SearchIndexDefinition ,
23992399 type ?: 'search' | 'vectorSearch'
24002400 ) : Promise < string > ;
2401- async createSearchIndex (
2402- description ?: SearchIndexDescription
2403- ) : Promise < string > ;
2401+ async createSearchIndex ( description : SearchIndexDescription ) : Promise < string > ;
24042402 @serverVersions ( [ '6.0.0' , ServerVersions . latest ] )
24052403 @returnsPromise
24062404 @apiVersions ( [ ] )
@@ -2409,62 +2407,55 @@ export default class Collection extends ShellApiWithMongoClass {
24092407 typeOrOptions ?: 'search' | 'vectorSearch' | SearchIndexDefinition ,
24102408 definition ?: SearchIndexDefinition
24112409 ) : Promise < string > {
2412- let indexName : string | undefined ;
2413- let indexType : string | undefined ;
2414-
2415- if ( typeof typeOrOptions === 'object' && typeOrOptions !== null ) {
2416- definition = typeOrOptions ;
2417- } else {
2418- indexType = typeOrOptions ;
2419- }
2410+ let indexDescription : SearchIndexDescription ;
24202411
24212412 if (
24222413 typeof nameOrOptions === 'object' &&
24232414 nameOrOptions !== null &&
24242415 nameOrOptions . definition
24252416 ) {
2426- indexName = nameOrOptions . name ;
2427- indexType = nameOrOptions . type ;
2428- definition = nameOrOptions . definition ;
2429- } else if ( typeof nameOrOptions === 'object' && nameOrOptions !== null ) {
2430- definition = nameOrOptions ;
2417+ indexDescription = nameOrOptions as SearchIndexDescription ;
24312418 } else {
2432- indexName = nameOrOptions ;
2419+ let indexName : string | undefined ;
2420+ let indexType : 'search' | 'vectorSearch' | undefined ;
2421+
2422+ if ( typeof typeOrOptions === 'object' && typeOrOptions !== null ) {
2423+ definition = typeOrOptions ;
2424+ } else {
2425+ indexType = typeOrOptions ;
2426+ }
2427+
2428+ if ( typeof nameOrOptions === 'object' && nameOrOptions !== null ) {
2429+ definition = nameOrOptions ;
2430+ } else {
2431+ indexName = nameOrOptions ;
2432+ }
2433+
2434+ indexDescription = {
2435+ name : indexName ?? 'default' ,
2436+ // Omitting type when it is 'search' for compat with older servers
2437+ ...( indexType &&
2438+ indexType !== 'search' && {
2439+ type : indexType as 'search' | 'vectorSearch' ,
2440+ } ) ,
2441+ definition : { ...definition } ,
2442+ } ;
24332443 }
24342444
2435- this . _emitCollectionApiCall ( 'createSearchIndex' , {
2436- indexName,
2437- indexType,
2438- definition,
2439- } ) ;
2445+ this . _emitCollectionApiCall ( 'createSearchIndex' , indexDescription ) ;
24402446 const results = await this . _mongo . _serviceProvider . createSearchIndexes (
24412447 this . _database . _name ,
24422448 this . _name ,
2443- [
2444- {
2445- name : indexName ?? 'default' ,
2446- // Omitting type when it is 'search' for compat with older servers
2447- ...( indexType &&
2448- indexType !== 'search' && {
2449- type : indexType as 'search' | 'vectorSearch' ,
2450- } ) ,
2451- definition : { ...definition } ,
2452- } ,
2453- ]
2449+ [ indexDescription ]
24542450 ) ;
24552451 return results [ 0 ] ;
24562452 }
24572453
24582454 @serverVersions ( [ '6.0.0' , ServerVersions . latest ] )
24592455 @returnsPromise
24602456 @apiVersions ( [ ] )
2461- // TODO(MONGOSH-1471): use SearchIndexDescription once available
24622457 async createSearchIndexes (
2463- specs : {
2464- name : string ;
2465- type ?: 'search' | 'vectorSearch' ;
2466- definition : Document ;
2467- } [ ]
2458+ specs : SearchIndexDescription [ ]
24682459 ) : Promise < string [ ] > {
24692460 this . _emitCollectionApiCall ( 'createSearchIndexes' , { specs } ) ;
24702461 return await this . _mongo . _serviceProvider . createSearchIndexes (
0 commit comments