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. :)
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});
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.