Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions packages/shell-api/src/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ describe('Collection', function () {
});
});

context('with options', function () {
context('with definition options', function () {
it('calls serviceProvider.createIndexes', async function () {
await collection.createSearchIndex({ mappings: { dynamic: true } });

Expand All @@ -2669,7 +2669,7 @@ describe('Collection', function () {
});
});

context('with name, options', function () {
context('with name, definition options', function () {
it('calls serviceProvider.createIndexes', async function () {
await collection.createSearchIndex('my-index', {
mappings: { dynamic: true },
Expand All @@ -2683,7 +2683,7 @@ describe('Collection', function () {
});
});

context('with name, options and type !== search', function () {
context('with name, definition options and type !== search', function () {
it('calls serviceProvider.createSearchIndexes', async function () {
await collection.createSearchIndex('my-index', 'vectorSearch', {
mappings: { dynamic: true },
Expand All @@ -2703,7 +2703,7 @@ describe('Collection', function () {
});
});

context('with name, options and type === search', function () {
context('with name, definition options and type === search', function () {
it('calls serviceProvider.createSearchIndexes', async function () {
await collection.createSearchIndex('my-index', 'search', {
mappings: { dynamic: true },
Expand All @@ -2717,7 +2717,7 @@ describe('Collection', function () {
});
});

context('with options and type but no name', function () {
context('with definition options and type but no name', function () {
it('calls serviceProvider.createSearchIndexes', async function () {
await collection.createSearchIndex(
{ mappings: { dynamic: true } },
Expand All @@ -2737,6 +2737,30 @@ describe('Collection', function () {
);
});
});

context('with description options', function () {
it('calls serviceProvider.createSearchIndexes', async function () {
await collection.createSearchIndex({
name: 'my-index',
type: 'vectorSearch',
definition: {
mappings: { dynamic: true },
},
});

expect(serviceProvider.createSearchIndexes).to.have.been.calledWith(
'db1',
'coll1',
[
{
name: 'my-index',
type: 'vectorSearch',
definition: { mappings: { dynamic: true } },
},
]
);
});
});
});

describe('createSearchIndexes', function () {
Expand Down
21 changes: 17 additions & 4 deletions packages/shell-api/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2388,17 +2388,30 @@ export default class Collection extends ShellApiWithMongoClass {
@apiVersions([])
// TODO(MONGOSH-1471): use SearchIndexDescription once available
async createSearchIndex(
indexName?: string | Document,
indexNameOrOptions?: string | Document,
type?: 'search' | 'vectorSearch' | Document,
definition?: Document
): Promise<string> {
let indexName: string | undefined;
if (typeof type === 'object' && type !== null) {
definition = type;
type = undefined;
}
if (typeof indexName === 'object' && indexName !== null) {
definition = indexName;
indexName = undefined;
if (
typeof indexNameOrOptions === 'object' &&
indexNameOrOptions !== null &&
indexNameOrOptions.definition
) {
indexName = indexNameOrOptions.name;
type = indexNameOrOptions.type;
definition = indexNameOrOptions.definition;
} else if (
typeof indexNameOrOptions === 'object' &&
indexNameOrOptions !== null
) {
definition = indexNameOrOptions;
} else {
indexName = indexNameOrOptions;
}

this._emitCollectionApiCall('createSearchIndex', { indexName, definition });
Expand Down
Loading