【发布时间】:2019-02-21 00:24:20
【问题描述】:
不知道是不是异步问题,所以有时候结果没有产品数据,只有类型数据。但是,有时它会有两个数据。
我的设置: Node JS、Express、Mongoose
router.get('/', function (req, res, next) {
var data = {};
Product.find().limit(4).populate({path: 'region_id', model: Region})
.then(function (doc) {
data.product = doc;
});
Type.find()
.then(function (doc) {
data.type = doc;
});
res.render('index', {title: 'Home', items: data});
});
如果我是正确的,那么如何确保在运行 render() 之前执行所有 find() 函数。
谢谢!
【问题讨论】:
标签: javascript node.js express asynchronous mongoose