Search code examples
mongodbspring-dataspring-data-mongodb

How to query by Id and by Boolean set to "True" using Spring Data JPA


In my Spring Repository (CRUD) I want to bypass the @Query annotation and query using Spring Data JPA Query Creation and Entity by its Id and where a boolean : Deleted of it is set to false. I tried :

ReturnType findByIdAndDeletedFalse(@Param("id") Long id)

My question is : is it possible to write it that way to do the query ? I am using MongoDB,

Thanks for the guidance.


Solution

  • https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#repository-query-keywords

    IsFalse is a repository query keyword and so you can use findByIdAndDeletedIsFalse