我怎么能得到所有值自定义字段mongoose的总和?

时间:2017-02-21 12:57:27

标签: node.js mongodb mongoose

我有架构:



{
	userName: String
	postCount: Number,
	commentCount: Number,
	abuseCount: Number,
}




我需要得到总和所有用户计算结果中的所有字段

例如



{
	"userName": "John"
	"postCount": 5,
	"commentCount": 1,
	"abuseCount": 4,
}, {
	"userName": "Bob"
	"postCount": 11,
	"commentCount": 41,
	"abuseCount": 3,
}, {
	"userName": "Alex"
	"postCount": 2,
	"commentCount": 15,
	"abuseCount": 6,
}




结果必须是〜



    {
    	"postCount": 18, (sum all postCount field users)
    	"commentCount": 57,
    	"abuseCount": 10,
    }




我怎么能这样做? THX!

0 个答案:

没有答案