fix(mongo): accept db["collection"] bracket accessors

This commit is contained in:
Loc Nguyen authored and GitHub committed 2026-09-11 10:50:44 +08:00
1 parent bad696ed11
commit e1e925fbab
3 files changed
+110

No files matched your search

+5
View File
@@ -202,6 +202,11 @@ export function parseCollectionMethodTarget(source: string, method: string): { c
if (getCollection) {
return { collection: getCollection[2]!, methodCallIndex: findChainedMethodCallIndex(source, method) };
}
// db["orders-2024"] reaches names that are not valid identifiers, the same way the shell does.
const bracket = new RegExp(`^db\\s*\\[\\s*(["'])(.*?)\\1\\s*\\]\\s*\\.\\s*${escapedMethod}\\s*\\(`).exec(source);
if (bracket) {
return { collection: bracket[2]!, methodCallIndex: findChainedMethodCallIndex(source, method) };
}
return null;
}