fix(mongodb): support array filters in updates

This commit is contained in:
zipg authored and GitHub committed 2026-07-12 23:13:36 +08:00
1 parent 0e779f9edc
commit 9a09bd49cb
15 files changed
+170 -14

No files matched your search

@@ -50,7 +50,7 @@ export type MongoCommand =
| ({ kind: "collectionStats" } & MongoCollectionStatsCommand)
| ({ kind: "use" } & MongoUseCommand)
| { 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 }
@@ -293,11 +293,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) {