server.get('/', function(req, res) {
Counter.find({}, function(err, result) {
if (!(err)) {
res.render('index', {'lol' : result});
}
});
});
I'm trying to get my app to display the contents of the whole database and this is what I came up with. Counter is a mongoose model. The database contains some items inserted prior to the execution of the program and one item inserted in the app itself.
Something is really iffy conceptually to me (I'm new to node), I think render() is being executed before find() which is why I'm not getting a result, but I can't think of a solution. Any help or push in the right direction is greatly appreciated. :)
res.renderwill definitely execute after thefindcompletes as you've correctly put it in thefindcallback. What's specifically not working?