简体   繁体   中英

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?

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});
  });
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM