Get data from mongodb (mongoose) to jade view

I'm stuck trying to get mongodb data in my jade views. I am new to node.js and I apologize if this seems silly! I see that in my table on the console:

Material.find(function (err, materials){ console.log(materials); }); 

But I want to transfer this data to my jade look

 app.get('/help', function(req, res){ res.render('help', {materials: materials}); }); 

How can i do this?

+7
source share
1 answer

You are on the right track! Just put the rendering in the callback from find :

 app.get('/help', function(req, res){ Material.find(function (err, materials){ res.render('help', {materials: materials}); }); }); 
+10
source

All Articles