spring-projects / spring-projects/spring-data-mongodb

ComparisonOperators.Lte seems to match undefined/null value in switch caseOperator

Open
#3,791 5 comments 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Aug 30, 2021.

status: ideal-for-contribution type: enhancement
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

ComparisonOperators.Lte seems to match undefined/null value in switch caseOperator

reactiveMongoTemplate.upsert(Query.query(
                                Criteria.where("id").is(b.getId())
                        ), AggregationUpdate.update()
                                .set("field.value").toValue(
                                        ConditionalOperators.switchCases(
                                                        CaseOperator.when(Gte.valueOf("field_priority")
                                                                        .greaterThanEqualToValue(b.getField().getPriority()))
                                                                .then("gte"),                                                
                                                        CaseOperator.when(Lte.valueOf("field_priority")
                                                                       .lessThanEqualToValue(b.getField().getPriority()))
                                                                .then("lt")
                                                )
                                                .defaultTo("default")
                                ), Bar.class)).flatMap(c -> Mono.just(foo));

if there is no document in the database we expect to run the default case, however we see the lte case is being ran.
We've tried fiddling with the order and gt, lt methods but none of them seem to accomplish what we're after.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.