mongoose가 데이터베이스에서 데이터를 가져 오기 전에 문제 뷰가 생성 된 곳을 도와 줄 수 있습니까? 나는 이미 기다리고 있지만 반응을 기다리지 않고 기다리고있다. 나는 그런 구문을 사용하는 이유를 알고의 cristmas 트리입니다Express JS mongoDB 비동기 대기
router.get('/', async(req, res, next)=> {
let products
try{
products = await Product.find({});
}catch(e){
console.log(e);
}
res.render('shop/index', { title: 'Express',products });
});
그러나 :
router.get('/', async(req, res, next)=> {
try{
const products = await Product.find({});
res.render('shop/index', { title: 'Express',products });
}catch(e){
console.log(e);
}
});
응답을 기다리지 않는다고 어떻게 결론 냈습니까? – Malice
모든 것을 얻은 후에 뷰 렌더가 필요합니다. 제품 정보 –
'console.log'를 사용하여 렌더링하기 전에 제품 로깅을 시도하십시오. – Malice