mongoDB

[mongodb mapreduce] add integer value

고요한하늘... 2011. 4. 8. 16:21

adding integer value.

input data

db.test2.save({"keyword":"다음",   "freq":10000})

db.test2.save({"keyword":"네이버", "freq":20000})

db.test2.save({"keyword":"다음",   "freq":55555})



map function

m = function(){ emit(this.keyword, { freq_sum:this.freq}); }


reduce function

r = function(key, values){

   var total=0

   values.forEach(function(x){

     total += x.freq_sum

   })

   return {"freq_sum": total };

}



call map/reduce

db.test2.mapReduce(m,r, {out:"mr_result"}) 



out data

db.mr_result.find()

{ "_id" : "네이버", "value" : { "freq_sum" : 20000 } }

{ "_id" : "다음", "value" : { "freq_sum" : 65555 } }



'mongoDB' 카테고리의 다른 글

mongodb test  (0) 2011.06.22
[mongodb mapreduce] time grouping  (0) 2011.06.01
[mongodb mapreduce] string concatenate  (0) 2011.04.08
[mongodb] case study1  (0) 2011.03.22
[mongodb install] how to use mongodb  (0) 2011.03.22