spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Add support for $expr to Criteria query. [DATAMONGO-1845]

Open spring-projects-issues opened this issue 7 years ago • 2 comments

Christoph Strobl opened DATAMONGO-1845 and commented

Allow usage of Aggregation expressions in filter queries using $expr.

db.monthlyBudget.find( { $expr: { $gt: [ "$spent" , "$budget" ] } } )

Reference URL: https://docs.mongodb.com/manual/reference/operator/query/expr/

3 votes, 3 watchers

spring-projects-issues avatar Jan 09 '18 08:01 spring-projects-issues

What about adding an exprOperator method to Criteria that accepts an AggregationExpression and behave like orOperator and andOperator ? It allows to reuse all the aggregation operators already defined in spring-data-mongodb.

public Criteria exprOperator(AggregationExpression expression)

The example above could be written like this:

Criteria criteria = new Criteria()
    .exprOperator(
        ComparisonOperators.Gt
              .valueOf("spent")
              .greaterThan("budget")
    );

petitcl avatar Apr 01 '21 10:04 petitcl

opened over 4 years ago...would be good to get this.

davidb-e4s avatar Jul 19 '22 19:07 davidb-e4s