我想使用从用户集合中提交的用户名过滤事件,但不知何故使用正则表达式聚合无法返回零项。但对于描述、事件名称等其他字段,它工作正常。我错过了什么?
我的代码如下:
if (requestedData.searchtext)
{
eventsFilterJson = {...eventsFilterJson, $or: [
{ user_name: { $regex: requestedData.searchtext, $options: "i" } },
]}
}
Event.aggregate([
{
$geoNear: {
near: point,
//maxDistance: maxDistance,
minDistance: last_distance,
key: locKey,
distanceField: "distance",
spherical: true,
distanceMultiplier: 1 / distanceMultiplier,
query: eventsFilterJson,
num:20
}
},
{
$lookup: {
from: "users",
let: { userId: '$$ROOT.user_id' },
pipeline: [
{
$match: {
$expr: { $eq: ["$_id", "$$userId"] }
}
},
{
$project:{
full_name:"$full_name"
}
}
],
as: "event.user"
}
},
{ $unwind: { path: "$event.user", preserveNullAndEmptyArrays: true } },
{
$project: {
user_name: {
$ifNull: ["$event.user.full_name", '']
},
}
}
])
.exec((err, results) => {
if (err) {
res.json(appfunctions.failResponse("msg_something_wrong"));
} else {
res.json(appfunctions.successResponse("msg_filter", results, req.user));
}
});