Home > Database > Mysql Tutorial > MongoDB中使用MapReduce进行分组统计

MongoDB中使用MapReduce进行分组统计

WBOY
Release: 2016-06-07 16:45:56
Original
1274 people have browsed it

MongoDB中使用MapReduce进行分组统计 最近在统计某一个时间段的url去重数,由于数据量巨大导致报错,提示: distinct failed: {

MongoDB中使用MapReduce进行分组统计

最近在统计某一个时间段的url去重数,,由于数据量巨大导致报错,提示:

distinct failed: {

"errmsg" : "exception: distinct too big, 16mb cap",

"code" : 17217,

"ok" : 0

} at src/mongo/shell/collection.js:1108


经过查阅资料,最终通过mapreduce来解决如下:

//定义map函数

map=function(){

    emit(this.url,{"count":1});

}

//定义reduce函数

reduce=function(key,values){

    var total=0;

    for(var i=0; i

        total+=values[i].count;

    }

    return {count:total}

}

//执行mapreduce函数,其中out的值是存储执行结果的集合

db.runCommand({"mapreduce":"visit","map":map,"reduce":reduce,"query":{"vtime":{"$gte":1412611200,"$lte":1413907119}},"out":"test.tmp"});

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

MongoDB入门必读(概念与实战并重)

Ubunu 14.04下MongoDB的安装指南

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

Nagios监控MongoDB分片集群服务实战

基于CentOS 6.5操作系统搭建MongoDB服务

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

本文永久更新链接地址:

本文永久更新链接地址:

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template