1
Not understanding what happened:
ready = function() {
groups = mongoose.model('groups', schemas.group);
groups.find({}, function(err, docs){
for(i in docs){
console.log(docs[i].name);
}
return docs;
});
}
console.log(ready());
EXIT:
undefined
Grupo A
Grupo B
Grupo C
within the ready() function it brings everything normally, but in the "console.log(ready())" it prints "Undefined"
Wasn’t he supposed to print it out? If anyone can help me I appreciate
People discover the problem. what’s happening is that the "ready" function returns before the callback "groups.find()" is called. anyone has any suggestions what I can do to resolve this?
– Henrique.Araujo
Explain what you want to do so that we can give a concrete example. You have an asynchronous proplema, very commun in the Node. What do you want to do with this ready? do you want to have a variable that tells you if the query has already been made?
– Sergio
this. A ready has the function to read all the records of the database and return them
– Henrique.Araujo