这是我的路线:
app.get('/my_restaurants', userController.getRestaurantId, restaurantController.getRestaurantById);
这是我的userController.getRestaurantId:
exports.getRestaurantId = (req, res, next) => {
// find user by id
User.findById(req.user.id, (err, user) => {
if (err) { return next(err); }
console.log("IN USER REST ID " + user.profile.restaurant);
req.restaurant_id = user.profile.restaurant;
});
return next();
}
这是我的restaurantController.getRestaurantById):
exports.getRestaurantById = (req, res, next) => {
var restaurant_id = req.restaurant_id;
console.log("REST ID " + restaurant_id);
Restaurant.findById(restaurant_id, (err, docs) => {
if (err) { return next(err); }
console.log("in find restaurant by id " + restaurant_id);
res.render('my_restaurants', {restaurant: docs});
});
};
这是我得到的确切错误: 无法阅读酒店' restaurant'为null
我已经检查过并且我的所有模型都没问题,我甚至在exports.getRestaurantId函数的console.log中获取了正确的objectId。
提前感谢您的帮助!