There are two ways to go about modeling queries in a domain service class. One approach is to create a method that explicitly produces the results for a report. In this approach, the complex logic needed to produce the report goes into the domain service class. This approach, which we call the Custom Query Method approach, is useful in situations where it is called frequently, and where you wish to hide the complexity of the logic from any calling program.
An alternative approach is to simply create a wrapper for existing pymongo functionality. We call this the Generic Query Method approach. This approach is useful if you wish to extend the flexibility of your domain service class, but places the burden on the calling program to formulate the appropriate query and logic to process the results.
We'll start by discussing the Generic Query Method approach.