http://kylebanker.com/blog/2009/12/mongodb-map-reduce-basics
문자열 결합( string concatenate )
input data
db.test1.save({"keyword":"다음", "date":"11/11"})
db.test1.save({"keyword":"네이버", "date":"04/21"})
db.test1.save({"keyword":"다음", "date":"12/01"})
map function
m = function(){ emit(this.keyword, { merge_date:this.date}); }
reduce function
r = function(key, values){
var all = [];
values.forEach(function(x){
all.push(x.merge_date)
})
return {"merge_date": all.join(", ")};
}
-> reduce 함수에 파라미터는 다음과 같이 넘어온다.
key : 다음, values : [{ merge_date : "11/11"}, { merge_date : "12/01} ]
key : 네이버, values : [{ merge_date : "04/21"} ]
call map/reduce
db.test1.mapReduce(m,r, {out:"mr_result"})
output data
db.mr_result.find()
{ "_id" : "네이버", "value" : { "merge_date" : "04/21" } }
{ "_id" : "다음", "value" : { "merge_date" : "11/11, 12/01" } }
'mongoDB' 카테고리의 다른 글
mongodb test (0) | 2011.06.22 |
---|---|
[mongodb mapreduce] time grouping (0) | 2011.06.01 |
[mongodb mapreduce] add integer value (0) | 2011.04.08 |
[mongodb] case study1 (0) | 2011.03.22 |
[mongodb install] how to use mongodb (0) | 2011.03.22 |