I'm new in node.js and mongodb. I set a mongodb collection called "article". I would like to display all the article of this collections in a jade template. I used this code :
server.js:
articles: db.article.find()
index.jade:
-for article in articles
.row
.twelve.columns
.panel
li= article.text
The jade is really basic but that will change. The fact is, when I run this code, the list in the jade template is empty and nothing is display. It looks like the variable 'articles' is empty.
Does anyone know how can I make that working?
Thanks
.find()
is asynchronous. you are using it synchronously.
function(req, res, next) {
db.articles.find().toArray(function(err, articles) {
res.render('page', {
articles: articles
}
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With