Creating custom finders

With Spring Data repositories, we are able to create queries to suit any situation. Earlier in this chapter, we saw findByName, which merely queries based on the domain object's name attribute.

The following table shows a more comprehensive collection of finders we can write with Spring Data MongoDB. To illustrate the breadth of these keywords, it presumes a domain model bigger than the Image class we defined earlier:

Finder Method



Query based on lastName


Query based on firstName and lastName


Query based on firstName and by a related manager's lastName

findTop10ByFirstName(...​) or ...

Get Developing Java Applications with Spring and Spring Boot now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.