fix(mongodb): support array filters in updates
This commit is contained in:
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) {
|
||||
|
||||
Reference in new issue
Block a user