Skip to content

Commit f4c69bc

Browse files
committed
fix: remove unsupported use cases
1 parent 3456adc commit f4c69bc

File tree

3 files changed

+39
-76
lines changed

3 files changed

+39
-76
lines changed

packages/service-provider-core/src/writable.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
DbOptions,
2525
OrderedBulkOperation,
2626
UnorderedBulkOperation,
27+
SearchIndexDescription,
2728
} from './all-transport-types';
2829
import type { ServiceProviderRunCommandCursor } from './cursors';
2930

@@ -312,7 +313,7 @@ export default interface Writable {
312313
*
313314
* @param {String} database - The db name.
314315
* @param {String} collection - The collection name.
315-
* @param {Object[]} indexSpecs the spec of the indexes to be created.
316+
* @param {Object[]} descriptions the spec of the indexes to be created.
316317
* @param {Object} options - The command options.
317318
* @param {DbOptions} dbOptions - The database options
318319
* @return {Promise}
@@ -385,12 +386,7 @@ export default interface Writable {
385386
createSearchIndexes(
386387
database: string,
387388
collection: string,
388-
// TODO(MONGOSH-1471): use SearchIndexDescription[] once available
389-
specs: {
390-
name: string;
391-
type?: 'search' | 'vectorSearch';
392-
definition: Document;
393-
}[],
389+
descriptions: SearchIndexDescription[],
394390
dbOptions?: DbOptions
395391
): Promise<string[]>;
396392

packages/shell-api/src/collection.spec.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,30 +2633,6 @@ describe('Collection', function () {
26332633
serviceProvider.createSearchIndexes.resolves(['index_1']);
26342634
});
26352635

2636-
context('without anything', function () {
2637-
it('calls serviceProvider.createIndexes', async function () {
2638-
await collection.createSearchIndex();
2639-
2640-
expect(serviceProvider.createSearchIndexes).to.have.been.calledWith(
2641-
'db1',
2642-
'coll1',
2643-
[{ name: 'default', definition: {} }]
2644-
);
2645-
});
2646-
});
2647-
2648-
context('with name', function () {
2649-
it('calls serviceProvider.createIndexes', async function () {
2650-
await collection.createSearchIndex('my-index');
2651-
2652-
expect(serviceProvider.createSearchIndexes).to.have.been.calledWith(
2653-
'db1',
2654-
'coll1',
2655-
[{ name: 'my-index', definition: {} }]
2656-
);
2657-
});
2658-
});
2659-
26602636
context('with definition options', function () {
26612637
it('calls serviceProvider.createIndexes', async function () {
26622638
await collection.createSearchIndex({ mappings: { dynamic: true } });

packages/shell-api/src/collection.ts

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)