[英]mongoose $regex on object or nested document
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
運算符永遠不會匹配location
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.