mongoose result's property is undefined, but exist

Viewed 45

I run into strange case. This is the second time when run into this problem. I added comment after every console.log to see the results:

    Spain.find()
    .limit(5)
    .exec((findErr, results) => {
        if(findErr){
            console.log('error while login', findErr);
        } else if(!results) {
            console.log('err with res');
        } else {
            let pool = 0;

            results.forEach((res, index) => {
                pool -= 1000;

                console.log(res); // {test1: 10, test2: 30, test3:20}

                let max = Math.max(res.test1, res.test2, res.test3);

                console.log(res.test1, res.test2, res.test3); // undefined undefined undefined
                console.log('max', max); // NaN
            });
        }
    });

Any idea, how this is possible?

UPDATE:

This code run as worker, maybe this is matter...

Node.js version: 7.10.1, mongoose version: 4.11.4

UPDATE 2: The code is within a typescript class. - Maybe parser error?

0 Answers
Related