简体   繁体   English

使用Spring的MongoDB聚合查询

[英]MongoDB aggregation query using spring

db.getCollection('questionbank').aggregate([
{ "$group": {
        "_id": {
        "technology": "$technology",
       "level":"$level",
         "type":"$type"
    },
    "Count": { "$sum": 1 }
}},
{ "$group": {
    "_id": "$_id.technology",
    "QuestionCount": { 
        "$push": { 
            "level":"$_id.level",
            "type":"$_id.type",
            "count": "$Count"
        },
    }
}}
])

I am trying to get the same output structure. 我试图获得相同的输出结构。

Can anyone please help me to write above query in spring. 谁能帮我在春季写上面的查询。 I have tried a lot but failed. 我已经尝试了很多但是失败了。

您可以使用以下内容。

group("technology", "level", "type").count().as("count"),            group("_id.technology")                .push(                    new BasicDBObject("level", "$_id.level")                        .append("type", "$_id.type")                        .append("count", "$count"))                .as("questionCount")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM