Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data from mongodb (mongoose) to jade view

I'm stuck trying to get mongodb data in my jade views. I'm a newbie with node.js and I apologize if this seems stupid! I can see what's in my table in the console:

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

But I want to pass that data to my jade view

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

How can I do that?

like image 539
Secco Jones Avatar asked Aug 12 '12 19:08

Secco Jones


1 Answers

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

app.get('/help', function(req, res){
  Material.find(function (err, materials){
    res.render('help', {materials: materials});
  });
});
like image 70
Michelle Tilley Avatar answered Sep 19 '22 14:09

Michelle Tilley