Skip to content

Commit 4e68c4a

Browse files
committed
two functions
1 parent 4116d42 commit 4e68c4a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DbOperationArgs, MongoDBToolBase, SearchIndexArgs } from "../mongodbTool.js";
2+
3+
export class CreateSearchIndexTool extends MongoDBToolBase {
4+
constructor() {
5+
super(...arguments);
6+
this.name = "create-search-index";
7+
this.description = "Create an Atlas Search index for a collection";
8+
this.argsShape = {
9+
...DbOperationArgs,
10+
name: SearchIndexArgs.name,
11+
type: SearchIndexArgs.type,
12+
analyzer: SearchIndexArgs.analyzer,
13+
mappings: SearchIndexArgs.mappings,
14+
};
15+
this.operationType = "create";
16+
}
17+
async execute({ database, collection, name, type, analyzer, mappings, }) {
18+
const provider = await this.ensureConnected();
19+
const indexes = await provider.createSearchIndexes(database, collection, [
20+
{
21+
name,
22+
type,
23+
definition: {
24+
analyzer,
25+
mappings,
26+
},
27+
},
28+
]);
29+
return {
30+
content: [
31+
{
32+
text: `Created the index "${indexes[0]}" on collection "${collection}" in database "${database}"`,
33+
type: "text",
34+
},
35+
],
36+
};
37+
}
38+
}

src/tools/mongodb/update/updateSearchIndex.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)