MongoVUE Group分组统计查询
格式:db.collection.group({ key, reduce, initial, [keyf,] [cond,] finalize })db.TestPaper.group({key : {"PaperType":true},cond : { "PaperType" : {"$in":[2,3,8]}},initial : {"count":
·
格式:
db.collection.group({ key, reduce, initial, [keyf,] [cond,] finalize })
count、sum、avg统计查询
db.TestPaper.group({
key : {"PaperType":true},
cond : { "PaperType" : {"$in":[2,3,8]}},
initial : {"count":0,"total":0},
reduce : function Reduce(doc, out) {
/*
// At start of Reduce, 'out' = intial value
out.count += doc.count;
*/
out.count+=1;//数量统计count
out.total+= doc.FaceQuestionCount;//求和统计sum
},
finalize : function Finalize(out) {
/*
// Make final updates or calculations
out.countSquare = out.count * out.count
*/
out.avg=out.total/out.count;//平均数
return out;
}
});
更多推荐
已为社区贡献2条内容
所有评论(0)