Home >Database >Mysql Tutorial > mongodb mapreduce小试

mongodb mapreduce小试

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:56:40972browse

最近由于产品业务的需求,需要使用一些数据量比较相对有点大的计算,顺便试试mongodb的mapreduce功能,感觉还不错 下面是官方提供的一个例子: $ ./ mongo db.things.insert( { _id : , ] } ); db.things.insert( { _id : ] } ); db.things.insert( { _id :

最近由于产品业务的需求,虚拟主机,香港服务器,需要使用一些数据量比较相对有点大的计算,香港虚拟主机,顺便试试mongodb的mapreduce功能,感觉还不错

 

下面是官方提供的一个例子:

$ ./mongo > db.things.insert( { _id : , ] } ); > db.things.insert( { _id : ] } ); > db.things.insert( { _id : , , ] } ); > db.things.insert( { _id : 4, tags : [] } ); > // map function > m = function(){ ... this.tags.forEach( ... function(z){ ... emit( z , { count : 1 } ); ... } ... ); ...}; > // reduce function > r = function( key , values ){ ... var total = 0; ... for ( var i=0; i ) ... total += values[i].count; ... return { count : total }; ...}; > res = db.things.mapReduce(m,r); > res {: : , : : : : 0} > db[res.result].find() {: , : {: 3}} {: , : {: 2}} {: , : {: 1}} > db[res.result].drop()

Statement:
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