Mongodb inquires many times and adds conditions continuously. How to handle it better

  mongodb, question

The list of queries (200,000 data) is first queried through condition 1. if the queried data is greater than 1, condition 2 is added (the query condition is condition 1 plus condition 2). if the result is greater than 1, the condition is added continuously. if it is equal to 1, the condition is terminated. if the result is 0, the result of the previous query is obtained. By analogy, multiple conditions are added. How can such a situation be handled better?
The idea now is to save the results of each query and query on the results, but if the results are very large, it cannot be realized. In addition, I have also thought about using aggregation, but I feel unable to handle it because of conditional judgment. Do you have any good methods?

The main question is, how does this process proceed?

Scene one

If the condition is more than one piece of data, the user selects the second condition to recheck it for the second time, and then recheck it; if the condition is more than one, the user selects the third condition to recheck it.
If this is the case, I think this is not a problem that the database needs to solve, but rather a problem of how you guide users to operate. A simple implementation can do this:

  • AJAX loads the query result. If the result of the next query is 0, do not update the current page. Instead, update the results on the page.

It is not necessary to consider the problem of retaining the results of the last time, only the conditions of the last time should be retained, and retaining the results is not beneficial to the efficiency of the database or the development complexity.

Scene 2

If the user gives n conditions in sequence at one time, there is only one record when you need to find out how many conditions.
If this is the case, it is also unnecessary to consider the problem of retaining the intermediate results. You can consider checking backwards, using the most conditions first, and subtracting one condition if there is no result until there is a result, that is the result you want.