[英]mongoose $regex on object or nested document
const AdressSchema = new Schema(
{
title: {
type: String,
required: true,
},
location: {
type: Object,
required: true,
},
})
location is where I want to find any matching expression位置是我想找到任何匹配表达式的地方
this is how I do it but returns empty result我就是这样做的,但返回空结果
async get() {
return this.Model.find($or: [{ title: { $regex: regex } },{location: { $regex: regex } }])
}
Regular expressions match strings.正则表达式匹配字符串。
MongoDB query language operators are type sensitive. MongoDB 查询语言运算符是类型敏感的。
type: Object
is not a string. type: Object
不是字符串。
Therefore the $regex
operator will never match a location
.因此$regex
运算符永远不会匹配location
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.