Simplify usage of user provided aggregation operations.

Introduce Aggregation.stage which allows to use a plain JSON String or any valid Bson representation to be used within an aggregation pipeline stage, without having to implement AggregationOperation directly.
The change allows to make use of driver native builder API for aggregates.

Original pull request: #4059.
Closes #4038
This commit is contained in:
Christoph Strobl
2022-05-20 09:44:45 +02:00
committed by Mark Paluch
parent 1184d6ee2d
commit ee076ec02f
15 changed files with 342 additions and 24 deletions

View File

@@ -126,6 +126,26 @@ At the time of this writing, we provide support for the following Aggregation Op
Note that the aggregation operations not listed here are currently not supported by Spring Data MongoDB. Comparison aggregation operators are expressed as `Criteria` expressions.
[TIP]
====
Unsupported aggregation operations/operators can be provided by implementing either `AggregationOperation` or `AggregationExpression`.
`Aggregation.stage` is a shortcut for registering a pipeline stage by providing its JSON or `Bson` representation.
[source,java]
----
Aggregation.stage("""
{ $search : {
"near": {
"path": "released",
"origin": { "$date": { "$numberLong": "..." } } ,
"pivot": 7
}
}
}
""");
----
====
[[mongo.aggregation.projection]]
=== Projection Expressions