【发布时间】:2015-09-27 11:31:26
【问题描述】:
我需要在每条新闻上获得用户的喜欢和 cmets。有这个查询:
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'}});
全部完成,但我无法获得正常的结果...所有看起来像图片:
我怎样才能得到漂亮的阅读结果?
【问题讨论】:
-
显示原始文档的样本以及您希望得到的结果。文本和不是屏幕截图。看起来您正在运行两个 mapReduce 操作,我敢打赌您不需要这样做。
标签: javascript mongodb view mapreduce