I'm trying to put data into an object. Although this object in loop has value, this object out of the loop hasn't value (empty). I had instance object global variable obj
. What's wrong with me?
p.s : findOne is a mongoose's method. (mongodb).
var obj = [];
for(var i = 0;i<anotherObj.length;i++){
var id = anotherObj[i].id;
model.findOne({_id:id},function(err,user){
if(!err){
obj.push(user);
console.log(obj); /* <= it has value */
}
})
}
console.log(obj); /* <= this is null */