fix(mongodb): support array filters in updates

This commit is contained in:
zipg
2026-07-12 23:13:36 +08:00
committed by GitHub
parent 0e779f9edc
commit 9a09bd49cb
15 changed files with 170 additions and 14 deletions
+6 -3
View File
@@ -1163,6 +1163,7 @@ async function executeMongoWrite(config: ConnectionConfig, command: MongoWriteCo
filter_json: command.filter,
update_json: command.update,
many: command.many,
options_json: command.options,
});
return { affectedRows: result.affected_rows };
}
@@ -1316,7 +1317,7 @@ interface MongoCollectionStatsCommand {
export type MongoWriteCommand =
| { kind: "insert"; collection: string; docsJson: string }
| { kind: "update"; collection: string; filter: string; update: string; many: boolean }
| { kind: "update"; collection: string; filter: string; update: string; options?: string; many: boolean }
| { kind: "delete"; collection: string; filter: string; many: boolean }
| { kind: "createIndex"; collection: string; keys: string; options?: string }
| { kind: "dropIndex"; collection: string; index: string }
@@ -1465,11 +1466,13 @@ export function parseMongoWriteCommand(input: string): MongoWriteCommand | null
const target = parseCollectionMethodTarget(source, method);
if (!target) continue;
const args = parseMethodArgs(source, target.methodCallIndex);
if (!args || args.length !== 2) return null;
if (!args || args.length < 2 || args.length > 3) return null;
const filter = normalizeJsonArgument(args[0]);
const update = normalizeJsonArgument(args[1]);
if (!filter || !update) return null;
return { kind: "update", collection: target.collection, filter, update, many: method === "updateMany" };
const options = args[2]?.trim() ? normalizeJsonArgument(args[2]) : undefined;
if (args[2]?.trim() && !options) return null;
return { kind: "update", collection: target.collection, filter, update, ...(options ? { options } : {}), many: method === "updateMany" };
}
for (const method of ["deleteOne", "deleteMany"] as const) {
+1
View File
@@ -375,6 +375,7 @@ async function executeMongoWrite(config: ConnectionConfig, command: MongoWriteCo
filterJson: command.filter,
updateJson: command.update,
many: command.many,
optionsJson: command.options,
}),
});
const result = (await res.json()) as { affected_rows: number };