【发布时间】:2019-03-21 16:29:47
【问题描述】:
如果满足两个条件,我正在尝试使用aggregation 返回一个字段(在文档中),
我是在$project 阶段做的,并试图写成如下:
"conversionName" : { "$cond" : [ { "$and" : [ { "$eq" : [ "$webpage", "Product" ] }, { "$eq" : [ "$isConverted", true ] } ] }, "$conversion.name", 0 ] }
因此,如果网页是 Product 并且 isConverted 为 true,那么它会在此文档中显示 conversion.name 的值。
The current aggregation fails due to : "The $cond accumulator is a unary operator' on server main-shard-00-00-mhxad.gcp.mongodb.net:27017. "
聚合的其他部分工作得很好。
我可以通过什么方式返回带有$cond 推荐的值?如果没有 - 还有什么方法可以满足我的需求?
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework