These are chat archives for Automattic/mongoose

23rd
Dec 2018
bhasin11
@bhasin11
Dec 23 2018 09:01
Hey all, can anyone please help me!!!! How can I get the value of query result (r) in the outside variable (result) ?
var result = null;

model.findById(carId, function (err, docs) {
    if (docs) {
        var r = new components.Car;
        r.name = docs.name;

        result = r;
        console.log('found');
        console.log('result size inside ', result.length);
    }
    else {
        result = null;
    }
});

console.log('result size outside ', result.length);

Output:
found
result size inside 1
result size outside 0