How do i put multiple conditions inside spring data mongodb aggregation filter?

720 Views Asked by At

Mongodb states that it is possible to put multiple conditions inside cond of filter. Like this:

{
  $filter: {
     input: [ 1, "a", 2, null, 3.1, NumberLong(4), "5" ],
     as: "num",
     cond: { $and: [
        { $gte: [ "$$num", NumberLong("-9223372036854775807") ] },
        { $lte: [ "$$num", NumberLong("9223372036854775807") ] }
      ] }
  }
}

Source: - https://docs.mongodb.com/manual/reference/operator/aggregation/filter/

I would like to do the same inside spring data mongodb. I have this aggregation:

val aggregation = Aggregation.newAggregation(
    project()
        .and(
        filter("some")
            .`as`("some")
            .by(
                ComparisonOperators.Lte.valueOf("some.field").lessThanEqualToValue(2000)  
/* here i would like to put "and" like .and(valueOf("some.field").greaterThanValue(1000) but it does not exists on returned value of valueOf*/
            )
        )

)

How can i do this ? I was looking for some "and" function on the level of "by" or "filter" but it does not exists. Adding another and will override my previous value (if for example i would like to filter using range of some.field or by multiple fields). How do i do this for multiple fields ?

0

There are 0 best solutions below