繁体   English   中英

mongoose $regex 上 object 或嵌套文档

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM