Reputation: 107
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. :)
Upvotes: 0
Views: 175
Reputation: 191
What is your view code?
Your implementation is correct, you should try to do debug.
server.get('/', function(req, res) {
Counter.find({}, function(err, result) {
if (!(err)) {
console.log('Debug: ' + JSON.stringify(result) );
res.render('index', {lol : result});
}
});
});
Upvotes: 2