fix(admin): partial _id fuzzy search via $expr + $toString + $regexMatch
This commit is contained in:
@@ -88,10 +88,10 @@ export class AdminController {
|
|||||||
{ email: { $regex: escaped, $options: 'i' } },
|
{ email: { $regex: escaped, $options: 'i' } },
|
||||||
{ wxOpenid: { $regex: escaped, $options: 'i' } },
|
{ wxOpenid: { $regex: escaped, $options: 'i' } },
|
||||||
]
|
]
|
||||||
// 支持按 MongoDB _id 搜索(24位 hex)
|
// 支持按 _id 模糊搜索(ObjectId → string → regex)
|
||||||
if (/^[0-9a-f]{24}$/i.test(keyword)) {
|
filter.$or.push({
|
||||||
filter.$or.push({ _id: keyword })
|
$expr: { $regexMatch: { input: { $toString: '$_id' }, regex: escaped, options: 'i' } },
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
const skip = (Math.max(1, +page) - 1) * +limit
|
const skip = (Math.max(1, +page) - 1) * +limit
|
||||||
const [users, total] = await Promise.all([
|
const [users, total] = await Promise.all([
|
||||||
|
|||||||
Reference in New Issue
Block a user