@Retention(value=RUNTIME) @Target(value={METHOD,ANNOTATION_TYPE}) @Documented public @interface Aggregation
Aggregation
annotation can be used to annotate a Repository
query method so that it runs the pipeline()
on invocation.
Repository
domain type to consider
field
mappings and may contain simple placeholders
?0
as well as SpelExpressions
.
Sort
and Pageable
arguments are applied at the end of the pipeline or can be defined manually as part of it.@AliasFor(value="pipeline") public abstract String[] value
pipeline()
. Defines the aggregation pipeline to apply.pipeline()
@AliasFor(value="value") public abstract String[] pipeline
// aggregation resulting in collection with single value @Aggregation("{ '$project': { '_id' : '$lastname' } }") List<String> findAllLastnames(); // aggregation with parameter replacement @Aggregation("{ '$group': { '_id' : '$lastname', names : { $addToSet : '$?0' } } }") List<PersonAggregate> groupByLastnameAnd(String property); // aggregation with sort in pipeline @Aggregation(pipeline = {"{ '$group': { '_id' : '$lastname', names : { $addToSet : '$?0' } } }", "{ '$sort' : { 'lastname' : -1 } }"}) List<PersonAggregate> groupByLastnameAnd(String property); // Sort parameter is used for sorting results @Aggregation("{ '$group': { '_id' : '$lastname', names : { $addToSet : '$?0' } } }") List<PersonAggregate> groupByLastnameAnd(String property, Sort sort); // Pageable parameter used for sort, skip and limit @Aggregation("{ '$group': { '_id' : '$lastname', names : { $addToSet : '$?0' } } }") List<PersonAggregate> groupByLastnameAnd(String property, Pageable page); // Single value result aggregation. @Aggregation("{ '$group' : { '_id' : null, 'total' : { $sum: '$age' } } }") Long sumAge(); // Single value wrapped in container object @Aggregation("{ '$group' : { '_id' : null, 'total' : { $sum: '$age' } } }) SumAge sumAgeAndReturnAggregationResultWrapperWithConcreteType(); // Raw aggregation result @Aggregation("{ '$group' : { '_id' : null, 'total' : { $sum: '$age' } } }) AggregationResults<org.bson.Document>> sumAgeAndReturnAggregationResultWrapper();
public abstract String collation
// Fixed value @Aggregation(pipeline = "...", collation = "en_US") List<Entry> findAllByFixedCollation(); // Fixed value as Document @Aggregation(pipeline = "...", collation = "{ 'locale' : 'en_US' }") List<Entry> findAllByFixedJsonCollation(); // Dynamic value as String @Aggregation(pipeline = "...", collation = "?0") List<Entry> findAllByDynamicCollation(String collation); // Dynamic value as Document @Aggregation(pipeline = "...", collation = "{ 'locale' : ?0 }") List<Entry> findAllByDynamicJsonCollation(String collation); // SpEL expression @Aggregation(pipeline = "...", collation = "?#{[0]}") List<Entry> findAllByDynamicSpElCollation(String collation);
String
by default.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.