【发布时间】:2020-07-09 23:00:00
【问题描述】:
如何在lookup 的pipeline 阶段执行regex 搜索?
{
$lookup: {
from: 'collection',
let: {variable: '$localVariable', name: '$name'},
pipeline:[{
$match:{
$expr:{
$and: [
{'$name': {$regex: '.*$$name.*', $options: 'i'}},
{$in: ['$_id', '$$variable']}
]
}
}
}],
as: 'newDocument'
}
},
我已经尝试了几件事,我很确定应该将正则表达式阶段包装在另一个运算符中,只是不确定是哪一个?
【问题讨论】:
-
$expr用于使用聚合运算符执行操作。因此,请尝试使用 aggregation regex operators 之一。
标签: mongodb