0

I updated my Spring Data Mongodb reactive example to the latest Spring Boot(2.5.6), there is a findByKeyword method to use regex to match Post title and content.

 Flux<Post> findByKeyword(String q) {
    var reg = ".*" + q + ".*";
    return template.find(query(where("title").regex(reg).orOperator(where("content").regex(reg))),
        Post.class);
  }

And add a test method to verify it, it did not work in the latest version.

  public void testFindByKeyword() {
    this.postRepository.findByKeyword("title")
        .skip(0)
        .take(10)
        .log()
        .as(StepVerifier::create)
        .expectNextCount(10)
        .verifyComplete();
  }

In another method findByTitleContains, it did not use orOperator and worked well.

I am not sure what is changed in orOperator the past versions, it was working well in the old versions(Spring Boot 2.1 or 2.2).

Hantsy
  • 8,006
  • 7
  • 64
  • 109
  • Can you update your question by also mentioning the old and new versions? – cagdasalagoz Nov 14 '21 at 06:18
  • the above creates a query like that connects `title` to an `OR` criteria array with only one element. In which version did this work before? Also please try something like `new Criteria().orOperator(where("title").regex(reg), where("content").regex(reg))` – Christoph Strobl Nov 16 '21 at 09:41

0 Answers0