DATAMONGO-2449 - Evaluate allowDiskUse added to Meta annotation when executing derived Aggregation.

@Meta(allowDiskUse...) allows to set the according aggregation option when executing a String based annotation via a repository definition.

Original pull request: #827.
This commit is contained in:
Christoph Strobl
2020-01-07 09:01:24 +01:00
committed by Mark Paluch
parent f8ee9648da
commit 85519eb84d
6 changed files with 83 additions and 6 deletions

View File

@@ -11,7 +11,6 @@ The definition may contain simple placeholders like `?0` as well as https://docs
----
public interface PersonRepository extends CrudReppsitory<Person, String> {
@Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
List<PersonAggregate> groupByLastnameAndFirstnames(); <1>
@@ -74,6 +73,36 @@ To gain more control, you might consider `AggregationResult` as method return ty
<8> Like in <6>, a single value can be directly obtained from multiple result ``Document``s.
====
In some scenarios aggregations might require additional options like a maximum execution time, additional log comments or the permission to temporarily write data to disk.
Use the `@Meta` annotation to set those options via `maxExecutionTimeMs`, `comment` or `allowDiskUse`.
[source,java]
----
public interface PersonRepository extends CrudReppsitory<Person, String> {
@Meta(allowDiskUse = true)
@Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
List<PersonAggregate> groupByLastnameAndFirstnames();
}
----
Or use `@Meta` to create your own annotation as shown in the sample below.
[source,java]
----
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
@Meta(allowDiskUse = true)
@interface AllowDiskUse { }
public interface PersonRepository extends CrudReppsitory<Person, String> {
@AllowDiskUse
@Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
List<PersonAggregate> groupByLastnameAndFirstnames();
}
----
TIP: You can use `@Aggregation` also with <<mongo.reactive.repositories, Reactive Repositories>>.
[NOTE]