Say, I have a model with an array of values incoming,
[ { _id: 5a69e13780e4172d514ed906, hobbyname: 'Teaching', __v: 0 },
{ _id: 5a69e1477a40892d6416f906, hobbyname: 'Cricket', __v: 0 }]
var arr = [];
for(var i=0; i < someModel.length; i++){
Hobby.find({})
.then(function(hob){
arr[i] = someModel[i].hobbyname;
})
.catch(function(err){
console.log(err);
});
}
console.log(arr);
Presently its logging arr as [], i would like it to finish the query execution, pushing the values to the arr and then give me the result.
I have simplified my project scenario, just to keep it understandable, i am a new bie, requiring help, thanks in advance.