Answer the question
In order to leave comments, you need to log in
How to make multiple queries at once in mongodb?
Hello.
The page displays several categories of products. For each category, you have to make a request and wait for a response in the callback function. Those. before filling the template with data, you need to make sure that all requests have received answers, and this is an extra, not beautiful code.
Can I somehow get an object at once that would have something like this?
{
cat_1: {ответ на первый запрос},
cat_2: {ответ на второй запрос}
}
Answer the question
In order to leave comments, you need to log in
somewhere in your async function
return {
cat_1: await loadForCategory('cat_1'),
cat_2: await loadForCategory('cat_2'),
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question