With this annotation, we can specify a raw query as a Mongo JSON query string.
FindBy
@Query("{ 'name' : ?0 }") List<User> findUsersByName(String name);
List<User> users = userRepository.findUsersByName("Eric");
$regex
@Query("{ 'name' : { $regex: ?0 } }") List<User> findUsersByRegexpName(String regexp);
List<User> users = userRepository.findUsersByRegexpName("^A");
List<User> users = userRepository.findUsersByRegexpName("c$");
$lt and $gt
@Query("{ 'age' : { $gt: ?0, $lt: ?1 } }") List<User> findUsersByAgeBetween(int ageGT, int ageLT);
List<User> users = userRepository.findUsersByAgeBetween(20, 50);
References
https://www.baeldung.com/queries-in-spring-data-mongodb