Answer the question
In order to leave comments, you need to log in
MongoDB, can multiple queries be executed as one?
Perhaps a stupid question, but still .. There is a collection of "Users". There are three separate queries: to find out the number of users with the name Vasya, to find users who have registered today, and to find female users. These are three unrelated queries. But they are executed with one request to the backend (displayed in a dashboard with statistics). Now I'm doing three separate ones using Promise.all. Is there a tool in monge to execute them in one and get an array with answers for each?
Answer the question
In order to leave comments, you need to log in
It is possible to try to connect three requests through $or in one megarequest. Most likely, you will have to disassemble the result in the node code with pens into parts, where is Vasya, where are the girls. There is a chance that this second step can be simplified using the aggregation framework.
But why? Tomorrow the requirements will change, instead of girls it will be necessary to show old men, and you will have to understand the monstrous request and the code that serves it. Or it will be found out that users for today are selected incorrectly. Or, worst of all, it will be necessary to show users even a week in advance, and show old people not instead of girls, but next to them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question