[英]MapReduce and MongoDB
I need to get users likes & comments on each news. 我需要获得用户对每个新闻的喜欢和评论。 Have this query: 有这个查询:
comments_map = function() {
emit(this.path, {"user" : this.user, "comment_date" : this.date, "comment" : this.text});
};
likes_map = function() {
emit(this.path, {"user" : this.vote.user, "like" : this.vote.like});
};
r = function(key, values) {
var result = {
"path" : "",
"user" : "",
"comment_date" : "",
"like" : ""
}
values.forEach(function(value){
if(value.path !== null) {
result.path = value.path;
}
if(value.user !== null) {
result.user = value.user;
}
if(value.comment_date !== null) {
result.comment_date = value.comment_date;
}
if(value.comment !== null) {
result.comment = value.comment;
}
if(value.like !== null) {
result.like = value.like;
}
});
return result;
}
res = db.comments.mapReduce(comments_map, r, {out : {reduce : 'joined'}});
res = db.likes.mapReduce(likes_map, r, {out : {reduce : 'joined'}});
All done, but i cant' get normal results... All looks like on the picture: 全部完成,但我无法获得正常结果...所有看起来像图片上的:
How can i get pretty read result? 我如何获得漂亮的阅读结果?
So. 所以。 This was easy... we just need to type after own query db.joined.find();
这很容易...我们只需要在自己的查询后键入db.joined.find();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.