node.js - 对象或嵌套文档上的 mongoose $regex
问题描述
const AdressSchema = new Schema(
{
title: {
type: String,
required: true,
},
location: {
type: Object,
required: true,
},
})
位置是我想找到任何匹配表达式的地方
我就是这样做的,但返回空结果
async get() {
return this.Model.find($or: [{ title: { $regex: regex } },{location: { $regex: regex } }])
}
解决方案
正则表达式匹配字符串。
MongoDB 查询语言运算符是类型敏感的。
type: Object
不是字符串。
因此,$regex
运算符永远不会匹配 a location
。
推荐阅读
- asp.net - 使用asp.net webapi重置没有旧密码的密码
- python - requests/exchangelib SSLError - 主机名“outlook.office.de”不匹配
- aws-lambda - 如何在无服务器中将 api 端点参数传递给 lambda 函数
- android - 为 Android 的用户消息传递平台 SDK 加密传输中的用户数据
- excel - 在 SUMPRODUICT 中查看数组结果
- javascript - 如何使用 ChartJS 中嵌套对象的数据解析图表
- azure-ad-b2c - aadb2c90243:idps 客户端密钥/秘密未正确配置
- r - 为R中矩阵中列中的每个值提取列名
- latex - LaTeX 中导入文件的相对路径
- assembly - CVTTSD2SI - 截断指令 - 使用“不精确”结果的舍入?