SPRING CONCEPTS
Repository
Spring Concepts / Repository
A repository abstracts access to stored domain objects.
Understand the idea
Spring Data creates an implementation of a repository interface at runtime. MongoRepository supplies common operations such as save, findById, and delete. Derived method names describe queries, allowing basic data access without manually writing driver calls.
A concrete example
interface TodoRepository
extends MongoRepository<Todo, String> {}
findByIdAndOwnerId(id, ownerId)In the application
PersonalTodoRepository combines id and owner in the database query, which is crucial for user isolation.
save can insert an object without an id. Load an existing record before updating when a missing id must produce 404.