Node.js错误:RangeError:超出最大调用堆栈大小

时间:2017-04-11 11:44:45

标签: javascript node.js mongodb mongoose

我是NodeJs的新手,我在运行我的应用程序时正在处理一个问题。我正在尝试为图像竞赛制作一个页面,我想在主页上显示最新的评论,并附上他们的发布评论的图像。我得到的错误如下所示:RangeError: Maximum call stack size exceeded,对我的代码at model.<anonymous> (\rootproject\models\comment.js:15:16)进行了引用。

整个错误代码如下所示:

RangeError: Maximum call stack size exceeded
    at model.Document.set (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:526:
34)
    at model.set [as image] (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:19
01:25)
    at model.<anonymous> (C:\Users\Rares\Desktop\rootproject\models\comment.js:15:16)
    at VirtualType.applySetters (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\virtualtyp
e.js:94:25)
    at model.Document.set (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:694:
12)
    at model.set [as image] (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:19
01:25)
    at model.<anonymous> (C:\Users\Rares\Desktop\rootproject\models\comment.js:15:16)
    at VirtualType.applySetters (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\virtualtyp
e.js:94:25)
    at model.Document.set (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:694:
12)
    at model.set [as image] (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:19
01:25)
    at model.<anonymous> (C:\Users\Rares\Desktop\rootproject\models\comment.js:15:16)
    at VirtualType.applySetters (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\virtualtyp
e.js:94:25)
    at model.Document.set (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:694:
12)
    at model.set [as image] (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\document.js:19
01:25)
    at model.<anonymous> (C:\Users\Rares\Desktop\rootproject\models\comment.js:15:16)
    at VirtualType.applySetters (C:\Users\Rares\Desktop\rootproject\node_modules\mongoose\lib\virtualtyp
e.js:94:25)

这是我的comment.js文件代码:

var models = require('../models'),
async = require('async');

module.exports = {
newest: function(callback) {
    models.Comment.find({}, {}, {
            limit: 5,
            sort: {
                'timestamp': -1
            }
        },
        function(err, comments) {
            var attachImage = function(comment, next) {
                models.Image.findOne({
                        _id: comment.image_id
                    },
                    function(err, image) {
                        if (err) throw err;

                        comment.image = image;
                        next(err);
                    });
            };

            async.each(comments, attachImage,
                function(err) {
                    if (err) throw err;
                    callback(err, comments);
                });
        });

}
};

提前谢谢!

0 个答案:

没有答案