Answer the question
In order to leave comments, you need to log in
What is the best way to change the code?
What can be done about it? either do it synchronously or wait like that?
or somehow combine requests into one
let categories,products,seasons,sizes
categoryModel.find({}).then(a=>{
categories=a
productModel.find({}).then(b=>{
products=b
seasonModel.find({}).then(c=>{
seasons=c
sizeModel.find({}).then(d=>{
sizes=d
res.render("admin",{categories,products,seasons,sizes})
})
})
})
})
Answer the question
In order to leave comments, you need to log in
Approximately like this:
const queries = [
categoryModel.find({}),
productModel.find({}),
seasonModel.find({}),
sizeModel.find({})
];
Promise.all(queries).then(result => {
console.log(result);
}).catch(err => {
throw err;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question