我想写一个查询哪个组由parentId
,如果parentId
为null然后分组由productId
.I写了一个mongodb查询,它使用$ifNull
运算符在$group
运算符中来实现这个,这是查询。
db.collection.aggregate(
{
$match:{
$and : [
{"tenant_id":1}
{"product_type":1}
]
},
{
$group : {
"_id":{ $ifNull: [ "$parent_id", "$product_id" ] },
"data": {"$first" : "$$ROOT"}
}
},
{ $sort: {"data.created" : 1 } },
{$limit: 4},
{$skip:2}
}
)
我想将此查询转换为spring代码。以下代码将按字段parentId
分组,并且工作正常。
GroupOperation grpOperation = Aggregation.group("parentId")
但是我怎么能在qazxsw poi条件下写qazxsw poi条件呢?
ifNull
希望这是你正在寻找的。
group