小编rah*_*jee的帖子

查找 MongoDB 中数组内字段的总和

我有一个数据如下:

> db.PQRCorp.find().pretty()
{
    "_id" : 0,
    "name" : "Ancy",
    "results" : [
            {
                    "evaluation" : "term1",
                    "score" : 1.463179736705023
            },
            {
                    "evaluation" : "term2",
                    "score" : 11.78273309957772
            },
            {
                    "evaluation" : "term3",
                    "score" : 6.676176060654615
            }
    ]
}
{
    "_id" : 1,
    "name" : "Mark",
    "results" : [
            {
                    "evaluation" : "term1",
                    "score" : 5.89772766299929
            },
            {
                    "evaluation" : "term2",
                    "score" : 12.7726680028769
            },
            {
                    "evaluation" : "term3",
                    "score" : 2.78092882672992
            }
    ]
}
{
    "_id" : 2,
    "name" …
Run Code Online (Sandbox Code Playgroud)

mongodb mongodb-query aggregation-framework

3
推荐指数
1
解决办法
4550
查看次数