任何人都可以将该查询转换为 mongo for java (org.springframework.data.mongodb.core.MongoOperations)???
我无法在 Java 中进行此搜索。
谢谢。
db.respostas.aggregate([
{
"$group":{
"_id":{
"per":"$pergunta",
"res":"$resposta"
},
"respostaCount":{
"$sum":1
}
}
},
{
"$group":{
"_id":"$_id.per",
"respostas":{
"$push":{
"resposta":"$_id.res",
"count":"$respostaCount"
}
},
"count":{
"$sum":"$respostaCount"
}
}
},
{
"$sort":{
"count":-1
}
}
])
最佳答案
你可以尝试这样的事情。
Aggregation agg = newAggregation(
group(fields().and("per", "$pergunta").and("res", "$resposta")).count().as("respostaCount"),
group(fields("$_id.per")).push(new BasicDBObject("resposta", "$_id.res").append("count", "$respostaCount"))
.as("respostas").sum("respostaCount").as("count"),
sort(Sort.Direction.DESC, "count"));
关于java - 将查询 mongo 转换为 spring Mongooperations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40517452/