Spring Data Aggregation ConditionalOperators条件和值均为空

时间:2018-10-10 13:03:04

标签: spring mongodb aggregation-framework spring-data-mongodb

在Spring Data中,我该怎么做?

if(x==null){
  return null; 
}else{
  return x.property;
}

为了具有if / else结构,我尝试了以下条件:

ConditionalOperators.Cond
    .when(ComparisonOperators.Eq.valueOf("x").equalToValue(null))
    .then(null)
    .otherwise("x.property")

但这不适用于null条件或then中的null。

适当的运算符可能是ConditionalOperators.IfNull,但没有otherwise

有什么建议吗?

0 个答案:

没有答案