Tuesday 11 April 2017

Node.js error : RangeError: Maximum call stack size exceeded

I'm new to NodeJs and I'm dealing with an issue while running my application.I'm trying to make a page for an image contest and I want to show on the homepage the newest comments,attaching to them the image where the comments were posted. The error that I get looks like this: RangeError: Maximum call stack size exceeded, making refference to my code at model.<anonymous> (\rootproject\models\comment.js:15:16).

The entire error code looks like this:

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)

Here is my code for comment.js file:

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

}
};

Thank you in advance!



via Iacob Rares

No comments:

Post a Comment