У меня есть эти коллекции
Код: Выделить всё
@Data
@Builder
@Document(collection = "subject")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Subject {
@Id
private String id;
@Field("full_name")
private String fullName;
@Field("subject_yupe")
@DocumentReference(lazy = true)
private SubjectType subjectType;
// other fields
}
@Data
@Builder
@Document(collection = "subjecttype")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SubjectType {
@Id
private String id;
@Indexed(unique = true)
@Field("name")
private String name;
}
Код: Выделить всё
@Repository
public interface SubjectRepository extends MongoRepository, QuerydslPredicateExecutor, QuerydslBinderCustomizer {
@Override
default void customize(QuerydslBindings bindings, QSubject subject) {
bindings.bind(String.class).first((StringPath path, String value) -> path.containsIgnoreCase(value));
}
}
Код: Выделить всё
@GetMapping("/search")
public ResponseEntity search(@QuerydslPredicate(root = Subject.class) Predicate predicate) {
log.debug("REST request to search Subject by parameters: {}", predicate);
// call the service that calls the repository and cast the result as List and map it
return ResponseEntity.ok(subjectService.findAll(predicate));
}
Код: Выделить всё
2022-12-12 21:58:31.505 DEBUG 5816 --- [nio-8080-exec-4] o.s.data.mongodb.core.MongoTemplate : find using query: { "full_name" : { "$regularExpression" : { "pattern" : ".*\\Qgius\\E.*", "options" : "i"}}} fields: Document{{}} for class: class it.XXXXXXXXX.collections.Subject in collection: subject
Код: Выделить всё
2022-12-12 22:03:09.590 DEBUG 5816 --- [nio-8080-exec-7] o.s.data.mongodb.core.MongoTemplate : find using query: { "subject_type.name" : { "$regularExpression" : { "pattern" : ".*\\QEntit\\E.*", "options" : "i"}}} fields: Document{{}} for class: class it.XXXXXXXXX.collections.Subject in collection: subject
Код: Выделить всё
2022-12-12 22:05:25.211 DEBUG 5816 --- [io-8080-exec-10] o.s.data.mongodb.core.MongoTemplate : find using query: { "subject_type" : { "$regularExpression" : { "pattern" : ".*\\Q63905c45051ce75d9b060edf\\E.*", "options" : "i"}}} fields: Document{{}} for class: class it.XXXXXXXXX.collections.Subject in collection: subject
Подробнее здесь: https://stackoverflow.com/questions/747 ... -and-web-s