求大神指导: 数据: { "_id" : ObjectId(“5832b48b2f908f6afb2c410c”), “sid” : “1700”, “stid” : “1000045449”, “atype” : “1”, “out_from” : “” } { "_id" : ObjectId(“5832b48b2f908f6afb2c410d”), “sid” : “1700”, “stid” : “1000045449”, “atype” : “2”, “out_from” : “” } { "_id" : ObjectId(“5832b48b2f908f6afb2c410e”), “sid” : “1700”, “stid” : “1000045449”, “atype” : “3”, “out_from” : “” } { "_id" : ObjectId(“5832b48b2f908f6afb2c410f”), “sid” : “1700”, “stid” : “1000045449”, “atype” : “0”, “out_from” : “” }
mapreduce:
var map = function () { emit( { sid: this.sid, stid: this.stid, atype: this.atype }, {count: 1} ); }; var reduce = function (key, values) { total = 0; for (var i in values) { print(values[i]) total += values[i].count; }
return {"count": total};
};
其中: atype状态是:0,1,2,3,而1,2是属于一种类型,需要怎么写map,reduce把1,2归类成一种类型。