Closed codello closed 4 years ago
In order to not accidentally hog keyword argument names this proposal will be implemented with the following changes:
filter
argument. Users can pass a custom dict
to take advantage of the full filtering capability.Query
class (a subclass of dict
). This class adds the ability to easily combine queries using the operators &
, |
, -
, and ~
(the last two of which have identical behavior). Combining a query with a dict
should be possible.Query
can be constructed using the constructor (which behaves like the usual dict
constructor), factory methods (for queries spanning multiple fields like $jsonSchema
) or a special q
function.q
function (whose name is intentionally very short) can convert keyword arguments into query documents thereby covering the most frequent cases:
age__gt
to perform a $gt
search on the field age
. To improve future compatibility any query operators should be supported even if they do not exist in MongoDB yet. A conversion from snake_case to camelCase should be performed automatically.
Query operations should support some typical queries by implementing the following schema:
filter
. This enables advanced queries.age__le=20
to Filter for an age field that is less than 20. This may be generalized for arbitrary operators.