You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedAggregation.java
+6-4
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ public StringBasedAggregation(MongoQueryMethod method, MongoOperations mongoOper
Copy file name to clipboardExpand all lines: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
<1> Aggregation pipeline to group first names by `lastname` in the `Person` collection returning these as `PersonAggregate`.
619
630
<2> If `Sort` argument is present, `$sort` is appended after the declared pipeline stages so that it only affects the order of the final results after having passed all other aggregation stages.
620
631
Therefore, the `Sort` properties are mapped against the methods return type `PersonAggregate` which turns `Sort.by("lastname")` into `{ $sort : { '_id', 1 } }` because `PersonAggregate.lastname` is annotated with `@Id`.
621
632
<3> Replaces `?0` with the given value for `property` for a dynamic aggregation pipeline.
622
633
<4> `$skip`, `$limit` and `$sort` can be passed on via a `Pageable` argument. Same as in <2>, the operators are appended to the pipeline definition. Methods accepting `Pageable` can return `Slice` for easier pagination.
623
-
<5> Aggregation methods can return `Stream` to consume results directly from an underlying cursor. Make sure to close the stream after consuming it to release the server-side cursor by either calling `close()` or through `try-with-resources`.
624
-
<6> Map the result of an aggregation returning a single `Document` to an instance of a desired `SumValue` target type.
625
-
<7> Aggregations resulting in single document holding just an accumulation result like e.g. `$sum` can be extracted directly from the result `Document`.
634
+
<5> Aggregation methods can return interface based projections wrapping the resulting `org.bson.Document` behind a proxy, exposing getters delegating to fields within the document.
635
+
<6> Aggregation methods can return `Stream` to consume results directly from an underlying cursor. Make sure to close the stream after consuming it to release the server-side cursor by either calling `close()` or through `try-with-resources`.
636
+
<7> Map the result of an aggregation returning a single `Document` to an instance of a desired `SumValue` target type.
637
+
<8> Aggregations resulting in single document holding just an accumulation result like e.g. `$sum` can be extracted directly from the result `Document`.
626
638
To gain more control, you might consider `AggregationResult` as method return type as shown in <7>.
627
-
<8> Obtain the raw `AggregationResults` mapped to the generic target wrapper type `SumValue` or `org.bson.Document`.
628
-
<9> Like in <6>, a single value can be directly obtained from multiple result ``Document``s.
629
-
<10> Skips the output of the `$out` stage when return type is `void`.
639
+
<9> Obtain the raw `AggregationResults` mapped to the generic target wrapper type `SumValue` or `org.bson.Document`.
640
+
<10> Like in <6>, a single value can be directly obtained from multiple result ``Document``s.
641
+
<11> Skips the output of the `$out` stage when return type is `void`.
630
642
====
631
643
632
644
In some scenarios, aggregations might require additional options, such as a maximum run time, additional log comments, or the permission to temporarily write data to disk.
0 commit comments