我正在使用聚合方法来收集来自不同集合的数据。正则表达式用于实现对用户的搜索。 MongoDB文本搜索对我来说不是一个选择,因为它将需要创建索引,这会占用大量内存。查询如下:
Users.aggregate([
{
$match: {
$or: [
{email: new RegExp(searchTerm,'ig')},{'userLocation.country': new RegExp(searchTerm,'ig')}
]
}
},{
$lookup: {
from: 'orders',localField: 'id',foreignField: 'userid',as: 'orders'
}
}
])
searchTerm
是保存用户输入的变量。我添加了maxTimeMS
来防止正则表达式DDOS攻击。可以利用什么可能的方式?