【问题标题】:Mongodb Aggregate - how to reference other field in matchMongodb Aggregate - 如何在匹配中引用其他字段
【发布时间】:2020-03-02 00:32:21
【问题描述】:

我有一个聚合管道,需要通过匹配两个字段来过滤结果

使用字段引用不会产生任何结果

$match: {
  "item.setid": "$uid"
}

用字符串替换字段引用会返回结果

$match: {
  "item.setid": "example-set-id"
}

对象架构:

{
    uid: <string>,
    item: {
        setid: <string> // references the uid above
    }
}

【问题讨论】:

    标签: mongodb aggregation-framework


    【解决方案1】:

    比较文档本身的字段,需要使用$expr操作符

    $match: {
       $expr: {
         $eq: ["$item.setid", "$uid"]
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-30
      • 2020-04-18
      • 2014-10-03
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      相关资源
      最近更新 更多