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).