Twitter API에서 스트림 데이터를 가지고 있으며 데이터가 MongoDB에 문서로 저장되어 있다고 가정 해 보겠습니다. 내가 찾고자하는 것은 screen_name
의 수를 entities.user_mentions
아래에 둔다.Twitter 데이터 - MongoDB에서 가장 많이 언급 된 사용자 찾기
{
"_id" : ObjectId("50657d5844956d06fb5b36c7"),
"contributors" : null,
"text" : "",
"entities" : {
"urls" : [ ],
"hashtags" : [
{
"text" : "",
"indices" : [
26,
30
]
},
{
"text" : "",
"indices" : []
}
],
"user_mentions" : [
{
"name":"Twitter API",
"indices":[4,15],
"screen_name":"twitterapi",
"id":6253282, "id_str":"6253282"
}]
},
...
내가지도를 사용하는 시도가 감소 :
map = function() {
if (!this.entities.user_mentions.screen_name) {
return;
}
for (index in this.entities.user_mentions.screen_name) {
emit(this.entities.user_mentions.screen_name[index], 1);
}
}
reduce = function(previous, current) {
var count = 0;
for (index in current) {
count += current[index];
}
return count;
}
result = db.runCommand({
"mapreduce" : "twitter_sample",
"map" : map,
"reduce" : reduce,
"out" : "user_mentions"
});
그러나 그 아주 작동하지 ...
모자를 벗으십시오. Aggregate Framework를 사용하여 동일한 작업을 수행 할 수 있습니까? 'group()'함수는 무엇입니까? – chutsu
@chutsu : Aggregation Framework에서도 동일한 작업을 수행 할 수 있지만 결과는 인라인으로 제한되고 최대 문서 크기는 16Mb로 제한된다는 몇 가지주의 사항이 있습니다. 'group()'명령을 사용하는 것도 가능할 수 있지만, 이것 역시 몇 가지 제한이 있습니다. 접근법과 한계를 비교하기 위해 [MongoDB group(), $ group and MapReduce] (http://stackoverflow.com/questions/12337319/mongodb-group-group-and-mapreduce/12340283#12340283)를 참조하십시오. – Stennie
@chutsu : 집계 프레임 워크 예제를 추가했습니다. – Stennie