当前位置:数据库 > mongodb >>

Mongodb MapReduce示例1个

Mongodb MapReduce示例1个
 
Map:
[javascript] 
map=function(){emit(this.classid,1)}    
function () {    
    emit(this.classid, 1);    
}  
 
Reduce:
[javascript] 
reduce=function(key,values){    
    var x = 0;    
    values.forEach(function(v){x+=v});    
    return x;    
}    
 
执行:
[javascript] 
result=db.runCommand({    
    mapreduce:"students",    
    map:map,    
    reduce:reduce,    
    out:"students_result"    
});   
 
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,