Taking sum of “column” in MongoDB

后端 未结 7 536

In MySQL, I would simply go \"SELECT sum(pts) FROM table\" to get the sum of the pts column on the table. However, I am converting this application to MongoDB and cannot fin

7条回答
  •  没有蜡笔的小新
    2020-12-10 19:45

    Other answers have already given lot many sources. Just giving answer for asked question:

    db.YOUR_COLLECTTION.aggregate([ { 
        $group: { 
            _id: null, 
            total: { 
                $sum: "$type" 
            } 
        } 
    } ] )
    

提交回复
热议问题