我使用 mongoTemplate 查询我的 mongodb 数据库,并且我想在我的集合中进行一些计数。我想按 id 分组并包括条件计数。我在 mongoshell 中使用了这个查询
db.scenarios.aggregate([
{ $match: { bid: "build_1481711758" } },
{
$group: {
_id: "$bid",
nb: { $sum: 1 },
nbS: {
"$sum": {
"$cond": [
{ "$eq": ["$scst", true ] },
1, 0
]
}
},
nbE: {
"$sum": {
"$cond": [
{ "$eq": ["$scst", false ] },
1, 0
]
}
}
}
}
])
Run Code Online (Sandbox Code Playgroud)
它返回我想要的,但我不知道如何将其转换为 java mongotemplate。
请帮忙 :)
java mongodb mongodb-query aggregation-framework mongotemplate