アノテーションインターフェース Aggregation
@RetentionSE(RUNTIMESE)
@TargetSE({METHODSE,ANNOTATION_TYPESE})
@DocumentedSE
@ReadPreference
public @interface Aggregation
Aggregation
アノテーションを使用すると、Repository
クエリメソッドにアノテーションを付けて、呼び出し時に pipeline()
を実行することができます。 パイプラインステージは、field
マッピングを考慮して Repository
ドメイン型に対してマップされ、単純なプレースホルダー ?0
と SpelExpressions
が含まれる場合があります。
クエリメソッド Sort
および Pageable
引数はパイプラインの最後に適用されるか、パイプラインの一部として手動で定義できます。
- 導入:
- 2.2
- 作成者:
- Christoph Strobl
オプション要素の概要
オプション要素修飾子と型オプションの要素説明集計を実行するときに適用する照合を定義します。StringSE[]
適用する集計パイプラインを定義します。使用する読み取り設定のモード。StringSE[]
pipeline()
のエイリアス。
要素の詳細
value
pipeline()
のエイリアス。適用する集計パイプラインを定義します。- 戻り値:
- デフォルトでは空の配列です。
- 関連事項:
- デフォルト:
- {}
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();
- 戻り値:
- デフォルトでは空の配列です。
- デフォルト:
- {}
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
SE です。
- デフォルト:
- ""
readPreference
使用する読み取り設定のモード。この属性 (@Aggregation(pipeline = {... }, readPreference = "secondary")
) は次の別名です。@@Aggregation(pipeline = { ... }) @ReadPreference("secondary") List<PersonAggregate> groupByLastnameAnd(String property);
- 戻り値:
- インデックス名。
- 導入:
- 4.2
- 関連事項:
- デフォルト:
- ""