Annotation Interface Query
Annotation to declare finder queries directly on repository methods. Both attributes allow using a placeholder
notation of
?0, ?1 and so on.- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionDefines the collation to apply when executing the query.booleanReturns whether the query defined should be executed as count projection.booleanReturns whether the query should delete matching documents.booleanReturns whether the query defined should be executed as exists projection.Defines the fields that should be returned for the given query.Defines a default sort order for the given query.
NOTE: The so set defaults can be altered / overwritten using an explicitSortargument of the query method.Takes a MongoDB JSON string to define the actual query to be executed.
-
Element Details
-
value
String valueTakes a MongoDB JSON string to define the actual query to be executed. This one will take precedence over the method name then.- Returns:
- empty
Stringby default.
- Default:
- ""
-
fields
String fieldsDefines the fields that should be returned for the given query. Note that only these fields will make it into the domain object returned.- Returns:
- empty
Stringby default.
- Default:
- ""
-
count
boolean countReturns whether the query defined should be executed as count projection.- Returns:
- false by default.
- Since:
- 1.3
- Default:
- false
-
exists
boolean existsReturns whether the query defined should be executed as exists projection.- Returns:
- false by default.
- Since:
- 1.10
- Default:
- false
-
delete
boolean deleteReturns whether the query should delete matching documents.- Returns:
- false by default.
- Since:
- 1.5
- Default:
- false
-
sort
String sortDefines a default sort order for the given query.
NOTE: The so set defaults can be altered / overwritten using an explicitSortargument of the query method.@Query(sort = "{ age : -1 }") // order by age descending List<Person> findByFirstname(String firstname);- Returns:
- empty
Stringby default. - Since:
- 2.1
- Default:
- ""
-
collation
String collationDefines the collation to apply when executing the query.// Fixed value @Query(collation = "en_US") List<Entry> findAllByFixedCollation(); // Fixed value as Document @Query(collation = "{ 'locale' : 'en_US' }") List<Entry> findAllByFixedJsonCollation(); // Dynamic value as String @Query(collation = "?0") List<Entry> findAllByDynamicCollation(String collation); // Dynamic value as Document @Query(collation = "{ 'locale' : ?0 }") List<Entry> findAllByDynamicJsonCollation(String collation); // SpEL expression @Query(collation = "?#{[0]}") List<Entry> findAllByDynamicSpElCollation(String collation);- Returns:
- an empty
Stringby default. - Since:
- 2.2
- Default:
- ""
-