javascript - 如何使用带有正则表达式搜索选项的填充
问题描述
我正在尝试fullName
使用 mongoose 在填充字段上实现搜索,这里我使用如下查询,
let search = this.req.body.search ? this.req.body.search : '';
let response = await Miles.find(filter)
.collation({ locale: Config.collation }).sort(sortBy)
.populate('driverId', { fullName: 1, longitude: 1, latitude: 1, address: 1, match: { fullName: { $regex: `.*${search}.*` } } })
.skip(skip).limit(perPage);
但它抛出"Unknown expression $regex"
异常。谁能帮我解决这个问题。
如果有任何与搜索文本匹配的文档,我只需要那个或多个文档。
解决方案
推荐阅读
- php - 拼接函数php
- xml - 使用 DITA OT Epub 插件更改 epub 输出中的 xhtml 主题文件名
- c - 这两种操作有区别吗?
- java - Java SSL TrustManager 上的部分链验证
- python - 检查单元测试是否通过
- php - 无法在 SQL 中保存或更新数据库数据
- android - 在android中制作一个自定义的列表视图,显示公共汽车的轨迹
- sql-server - 将 sql server 2000 连接到 Visual Studio 2015
- ethereum - 在循环中发送 .send 请求只会设置循环的最后一个值 i 次
- php - 卷曲 HTTP 发布问题