Movie.findById這個方法里面的callback函數是如何取到真實的movie的值的呢?
app.get('/movie/:id', function(req, res){ var id = req.params.id; Movie.findById(id, function(err, movie){ res.render('detail', { title: movie.title, movie: movie }); }) }); 請問Movie.findById這個方法里面的function函數是如何取到真實的movie的值的呢?
2017-06-24
var query = Person.findOne({ 'name.last': 'Ghost' });
// selecting the `name` and `occupation` fields
query.select('name occupation');
// execute the query at a later time
query.exec(function (err, person) {
? if (err) return handleError(err);
? console.log('%s %s is a %s.', person.name.first, person.name.last, person.occupation) // Space Ghost is a talk show host.
})
上面是官方實例,findOne函數返回一個query對象,然后調用exec函數執行這個query,把獲取到的結果返回給回調函數