mongdb之mapreduce操作
程序员文章站
2022-04-16 20:57:29
...
统计sn,mac地址在栏目下的点播时长和点播次数
db.getCollection('collectcontents').mapReduce( function() { emit( {'sn':this.sn,'mac':this.mac,'columnID':this.actionInfo.columnID}, {'sn':this.sn,'mac':this.mac,'cpId':this.actionInfo.columnID,playcount:1,'consumeTime':this.actionInfo.consumeTime}); }, function(key, values) { var playtime = 0; for(var i = 0; i < values.length; i++){ playtime=playtime+values[i].consumeTime; } key.consumeTime=playtime; key.playcount = values.length; return key; }, { query:{action:"011",'actionInfo.status':7,time: {$gte: '2028-10-10 20:26:43', $lt: '2028-11-28 20:26:43'}}, out:"post_total" } );