0

I'm trying to render a page and pass a few variables across. I get an "undefined" error in browser and console shows the following GET request

GET/calendar?v=5708cc410e45c4603345c7a1 [object Object]

The route code is:

app.get('/calendar', isLoggedIn, function(req, res) {
    var owner = 0;
    user.find({user_id:req.query.v})
    .lean()
    .exec(function(err, data) {
      owner = data;
    })

    res.render('calendar.ejs', {
      user : req.user,
      message: req.flash('postMessage'),
      owner: owner
    });
});

The route is receiving the query from client. I get the same error if I replace res.render with res.json(data) so it might be a database issue? But the DB query code is correct as far as I can tell...

  • It looks like you try to render the response before the DB returns your data. try to do `.exec(function(err, data) { if (!err) res.render(...) }` and see what happens. – Wojciech Ptak Apr 10 '16 at 17:14
  • Show `calendar.ejs` content. And your code won't be work, you're using owner before it's initialized, `user.find` is async func. – alexmac Apr 10 '16 at 17:14

0 Answers0