【发布时间】:2020-02-19 21:07:08
【问题描述】:
var query = req.params.query;
const messages = await Message.aggregate([
{
$lookup: {
from: 'users',
localField: 'reference_id',
foreignField: '_id',
as: 'users'
}
},
{'text': {'$regex': `.*${query}.*`}}
])
收到错误“消息”:“参数必须是聚合管道运算符”,
我想从 users 表中加入 first_name 和 last_name,并根据 first_name、last_name 和 text 进行搜索,我该如何实现这一目标
【问题讨论】:
-
加入收藏或搜索时出现问题?
-
加入它得到问题如何使它正确,希望你理解我的问题
-
@Shivam :
text也是用户集合或message集合中的字段吗? -
是的文本是消息集合中的字段
-
只是让这个问题和那里的答案一样重复,how to work with $lookup and $regex search in mongodb
标签: mongodb