I don't know whether it is async problem so that sometimes the result had no product data but only type data. However, sometimes it will have both data.
My setup: 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});
});
If I am correct then how to make sure all the find() function is executed before running render().
Thanks!