feat(mongodb): support createIndex shell command (#2187)
This commit is contained in:
1 parent
4e012a9dd9
commit
b90e4fd64e
17 files changed
+374
-18
No files matched your search
@@ -135,6 +135,12 @@ test("parseMongoWriteCommand accepts supported write commands", () => {
|
||||
filter: '{"stale":true}',
|
||||
many: true,
|
||||
});
|
||||
assert.deepEqual(parseMongoWriteCommand('db.projects.createIndex({"email":1},{"unique":true,"name":"projects_email_unique"})'), {
|
||||
kind: "createIndex",
|
||||
collection: "projects",
|
||||
keys: '{"email":1}',
|
||||
options: '{"unique":true,"name":"projects_email_unique"}',
|
||||
});
|
||||
});
|
||||
|
||||
test("mongodb executeQuery blocks writes when writes are explicitly disabled", async () => {
|
||||
@@ -162,6 +168,31 @@ test("mongodb executeQuery blocks writes when writes are explicitly disabled", a
|
||||
else process.env.DBX_MCP_ALLOW_WRITES = oldAllowWrites;
|
||||
});
|
||||
|
||||
test("mongodb executeQuery treats createIndex as a write when writes are explicitly disabled", async () => {
|
||||
const oldAllowWrites = process.env.DBX_MCP_ALLOW_WRITES;
|
||||
process.env.DBX_MCP_ALLOW_WRITES = "0";
|
||||
await assert.rejects(
|
||||
executeQuery(
|
||||
{
|
||||
id: "mongo",
|
||||
name: "mongo",
|
||||
db_type: "mongodb",
|
||||
host: "127.0.0.1",
|
||||
port: 27017,
|
||||
username: "",
|
||||
password: "",
|
||||
database: "app",
|
||||
ssh_enabled: false,
|
||||
ssl: false,
|
||||
},
|
||||
'db.projects.createIndex({"email":1})',
|
||||
),
|
||||
/read-only/i,
|
||||
);
|
||||
if (oldAllowWrites === undefined) delete process.env.DBX_MCP_ALLOW_WRITES;
|
||||
else process.env.DBX_MCP_ALLOW_WRITES = oldAllowWrites;
|
||||
});
|
||||
|
||||
test("mongoDocumentsToQueryResult turns documents into rows", () => {
|
||||
assert.deepEqual(
|
||||
mongoDocumentsToQueryResult(
|
||||
|
||||
Reference in new issue
Block a user