odmantic
odmantic copied to clipboard
Aggregation support via the find method
Feature request
Context
engine.find
allows full flexibility to query anything matching the read operation query syntax, via the
*queries
parameter, by allowing to pass QueryExpression
along raw queries (dicts).
engine.find
uses collection.aggregate
internally, and therefore can allow an equal flexibility to use any aggregation stage matching the aggregation pipeline syntax
But, the function limits the use of aggregation stages to the ones defined explicitly via the function parameters:
limit, sort, skip
- for the $limit, $skip and $sort aggregation stages.
And *queries
- which are used inside the $match aggregation stage.
Solution
-
Support all aggregation stages, with a new
aggregations
parameter. Add the expressions in theaggregations
parameter to the pipeline outside the $match stage. -
For extra convenience, create
AggregationQueryExpression
, to support simple creation of aggregation stages. Ones not implemented will be passed toaggregations
as raw queries (dicts). -
Add more aggregation operators as
QueryExpression
.
Alternative solutions
Implement the db.collection.find()
method in engine.find
, and create an engine.aggregate
method for aggregations related operations.
Additional context
This will allow the user to use implemented odemantic functions for aggregation, reducing the need to use Raw query helpers
I would like to contribute this feature, can you assign it to me?
Agreed! I need it