odmantic icon indicating copy to clipboard operation
odmantic copied to clipboard

Aggregation support via the find method

Open EllieSapir opened this issue 1 year ago • 2 comments

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 the aggregations 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 to aggregations 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

EllieSapir avatar Feb 03 '24 16:02 EllieSapir

I would like to contribute this feature, can you assign it to me?

EllieSapir avatar Feb 03 '24 16:02 EllieSapir

Agreed! I need it

z0z0r4 avatar Jul 13 '24 10:07 z0z0r4