MongoDB가 MapReduce쪽으로 좀 더 강화를 하나 보네요.
http://blog.mongodb.org/post/16015854270/operations-in-the-new-aggregation-framework
http://www.mongodb.org/display/DOCS/Aggregation+Framework
차기버젼 그러니깐.. 2.1버젼에서 aggregation framework를 소개한답니다.
그동안 구렸던 JavaScript로 머리가 아팠는데 말이죠.
aggrefation framework는 크데 pipelinse 와 expressions 라는 두 가지 컨셉으로 이루어 집니다.
pipeline은 리눅스의 파이프와 유사하다고 보시면 됩니다. 일련의 operation을 순차적으로 연결하여 사용할 수 있습니다.
pipeline는
$match - document stream으로 부터 특정 문서를 filtering
$project - document의 필드를 넣거나 뺌으로서, 또는 필드값을 계산(기존필드 * 10 이런식으로) 문서를 reshape 합니다.
$limit - 문서 수 제한
$skip - 건너 뛸 문서 수
$unwind - 특정 조건으로 문서를 쪼개는 기능. 예제를 참조
For the examples that follow, imagine an article collection made up of documents that look like this:
Here is an example that demonstrates the effect of $unwind:{ title : "this is my title" , author : "bob" , posted : new Date() , pageViews : 5 , tags : [ "fun" , "good" , "fun" ] , comments : [ { author :"joe" , text : "this is cool" } , { author :"sam" , text : "this is bad" } ], other : { foo : 5 } });
Note the dollar sign ('$') in front of the name of the field to be unwound.db.runCommand( { aggregate : "article", pipeline : [ { $project : { author : 1 , /* include this field */ title : 1 , /* include this field */ tags : 1 /* include this field */ }}, { $unwind : "$tags" } ]});
If this pipeline were to be run on the single article above, this would be the result:
$group - 키를 기준으로 그룹핑하여 합산{ "result" : [ { "_id" : ObjectId("4e6e4ef557b77501a49233f6"), "title" : "this is my title", "author" : "bob", "tags" : "fun" }, { "_id" : ObjectId("4e6e4ef557b77501a49233f6"), "title" : "this is my title", "author" : "bob", "tags" : "good" }, { "_id" : ObjectId("4e6e4ef557b77501a49233f6"), "title" : "this is my title", "author" : "bob", "tags" : "fun" } ], "ok" : 1 }
$sort
위와 같은 명령어를 제공하는군여
점점 MongoDB가 사랑스럽니다.

