node.js - 模糊搜索中的“未定义正则表达式”错误
问题描述
正则表达式未定义
做了一些搜索,它说使用正则表达式而不是正则表达式,但它给了我一个数据库问题。我应该怎么做才能在我的网站上进行模糊搜索?
router.get("/", function(req, res){
if(req.query.search){
const regex = new RegExp(escapeRegex(req.query.search), 'gi');
} else{
// Get all campgrounds from DB
Campground.find({name:regex}, function(err, allCampgrounds){
if(err){
console.log(err);
} else {
res.render("campgrounds/index",{campgrounds: allCampgrounds, page: 'campgrounds'});
}
});
}
});
解决方案
推荐阅读
- docker - 使用 Dockerfile 挂载/下载 gdrive 文件夹
- redux - 为什么 redux devtools 在其 JSON 导出中转义引号?
- java - 在 Java 中放心地测试特定方法
- mysql - 我怎样才能得到上一个星期五和下一个星期四的日期?
- android - Android - 怎么知道,在宿主activity中,导航已经结束
- javascript - 更改 xclass 视图 extjs 6.2.1 现代
- scala - 错误:发现类型不匹配:Array[Byte] [error] required:Byte
- android - ADB install 命令的源代码在哪里?
- angular - 使用包含可观察到的检索令牌的拦截器设置授权标头
- javascript - 如何让用户使用使用 javascript 的按钮添加新字段?