返回

Mongodb:$regexMatch在转换数组$toString后无法按预期工作

发布时间:2022-05-04 04:36:09 262
# sql

我使用Mongo的$regexMatch操作符来查找至少部分字段与模式匹配的文档,这对根级别的字段很有效,但搜索文档中有一个数组,其中有一个数组字段。但如何将其用于数组字段?如果至少有一个数组元素与模式匹配,我想返回一个匹配。

db.companies.aggregate(
[{$geoNear: {
 near: {
  type: 'Point',
  coordinates: [
   -3.128145200960907,
   -59.99944718666838
  ]
 },
 maxDistance: 10000,
 distanceField: 'dist.calculated',
 spherical: true
}}, {$lookup: {
 from: 'flyers',
 localField: '_id',
 foreignField: 'company',
 as: 'flyers'
}}, {$project: {
 _id: 1,
 socialReason: 1,
 'profile.logo': 1,
 flyers: {
  $filter: {
   input: '$flyers',
   as: 'flyers_ativados',
   cond: {
    $eq: [
     '$$flyers_ativados.status',
     'Ativado'
    ]
   }
  }
 }
}}, {$project: {
 flyers: {
  $filter: {
   input: '$flyers',
   as: 'flyers_ativados',
   cond: {
    $or: [
     {
      $regexMatch: {
       input: '$$flyers_ativados.title',
       regex: 'kuka'
      }
     },
     {
      $regexMatch: {
       input: '$$flyers_ativados.description',
       regex: 'kuka'
      }
     },
     {
      $regexMatch: {
       input: {
        $toString: '$$flyers_ativados.tags'
       },
       regex: 'carne'
      }
     }
    ]
   }
  }
 }
}}])

MongoServerError:PlanExecutor在聚合过程中出错::原因::不支持在没有onError值的$convert中从数组到字符串的转换

非常感谢您的建议

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像