I’m trying to query my database but for some reason I never get results when I know there are 3 things into my database. I’ve made this function:
function toJson()
{
var test = [];
async.series({
rooms : function() { return Room.find(); }
}
, function(err, results) {
test = results.rooms;
});
return test;
}
How does this come ? I’m guessing it has something to do that mongoose his method (search) is async..
Thanks in advance.
toJsonis returning immediately, but thereturn test;happens immediately. You need to maketoJsontake a callback instead—you don’t even need to useasync.serieshere:This will kind of do what you want — but you shouldn’t ignore
errlike you’re proposing.