Bug
buildFindSelector in packages/core-users/src/module/configureUsersModule.ts builds an invalid MongoDB query when usernames or emails are passed:
if (usernames?.length) {
selector.username = {
$in: usernames.map((u) => insensitiveTrimmedRegexOperator(u)),
} as any;
}
if (emails?.length) {
selector['emails.address'] = {
$in: emails.map((e) => insensitiveTrimmedRegexOperator(e)),
} as any;
}
insensitiveTrimmedRegexOperator (in @unchainedshop/mongodb) returns an operator document { $regex: RegExp }. MongoDB allows plain regex values inside $in, but not operator documents, so any findUsers({ usernames: [...] }) / findUsers({ emails: [...] }) call fails with:
MongoServerError: cannot nest $ under $in
code: 2, codeName: 'BadValue'
Affects the released 4.8.22 — present on both the v4.8.x branch (configureUsersModule.ts L87–95) and master (L86–94). A patch on v4.8.x (→ 4.8.23) would be appreciated.
Repro
await modules.users.findUsers({ usernames: ['someuser'] });
// MongoServerError: cannot nest $ under $in
Suggested fix
Map to raw RegExp values instead of the { $regex } wrapper, e.g.:
$in: usernames.map((u) => insensitiveTrimmedRegexOperator(u).$regex)
or add a helper that returns the bare RegExp for use inside $in.
Bug
buildFindSelectorinpackages/core-users/src/module/configureUsersModule.tsbuilds an invalid MongoDB query whenusernamesoremailsare passed:insensitiveTrimmedRegexOperator(in@unchainedshop/mongodb) returns an operator document{ $regex: RegExp }. MongoDB allows plain regex values inside$in, but not operator documents, so anyfindUsers({ usernames: [...] })/findUsers({ emails: [...] })call fails with:Affects the released
4.8.22— present on both thev4.8.xbranch (configureUsersModule.tsL87–95) andmaster(L86–94). A patch onv4.8.x(→ 4.8.23) would be appreciated.Repro
Suggested fix
Map to raw
RegExpvalues instead of the{ $regex }wrapper, e.g.:or add a helper that returns the bare
RegExpfor use inside$in.