The problem is that you are writing Mongoose code as if it were synchronous, but you need to call res.render inside the run callback function, because that is when the request is executed. In your example, the render function will be called before the result is returned by the query.
Alternatively, you can pass the popmap variable as a local variable into the view:
app.get('/map/:id', function(req, res){ Map .findOne({ _id: req.map._id }) .populate('_editors') .run(function (err, popmap) { console.log('The editors are %s', popmap._editors); res.render('maps/show', { title: req.map.title, map: req.map, popmap: popmap
source share