簡體   English   中英

MapReduce和MongoDB

[英]MapReduce and MongoDB

我需要獲得用戶對每個新聞的喜歡和評論。 有這個查詢:

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'}});

全部完成,但我無法獲得正常結果...所有看起來像圖片上的:

在此處輸入圖片說明

我如何獲得漂亮的閱讀結果?

所以。 這很容易...我們只需要在自己的查詢后鍵入db.joined.find();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM