Spring data mongodb repository findAll field exclusion Spring data mongodb repository findAll field exclusion spring spring

Spring data mongodb repository findAll field exclusion


Adding an empty filter criteria will do the trick for you:

@Query(value = "{}", fields = "{'objectContentAsJson':0}")Page<ObjectHistory> findAll(Pageable pageable);

Apparently, when you do not specify the value parameter to filter results, Spring Data tries to derive a query from the method name and somehow, does not recognize the special meaning of findAll.


Since you are not providing a value field to your @Query annotation, Spring will try to convert the method name findAll to a query which is not respecting the Query Creation Specification from Spring.Please look a the Specs here.

This should work for you :

@Query(value = "{}", fields = "{'objectContentAsJson':0}")Page<ObjectHistory> findAll(Pageable pageable);