W obecnej wersji Mongoose exec()
metoda zwraca obietnicę, więc możesz wykonać następujące czynności:
exports.process = function(r) {
return Content.find({route: r}).exec();
}
Następnie, gdy chcesz uzyskać dane, powinieneś je asynchronicznie:
app.use(function(req, res, next) {
res.local('myStuff', myLib.process(req.path));
res.local('myStuff')
.then(function(doc) { // <- this is the Promise interface.
console.log(doc);
next();
}, function(err) {
// handle error here.
});
});
Aby uzyskać więcej informacji o obietnicach, przeczytałem niedawno wspaniały artykuł:http://spion.github.io/posts/why-i-am-switching-to-promises.html