Class ProjectionOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.ProjectionOperation
- All Implemented Interfaces:
AggregationOperation
,FieldsExposingAggregationOperation
Encapsulates the aggregation framework
$project
-operation.
Projection of field to be used in an Aggregation
. A projection is similar to a Field
inclusion/exclusion but more powerful. It can generate new fields, change values of given field etc.
We recommend to use the static factory method Aggregation.project(Fields)
instead of creating instances of
this class directly.
- Since:
- 1.3
- Author:
- Tobias Trelle, Thomas Darimont, Oliver Gierke, Christoph Strobl, Mark Paluch
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder forarray
projections.static class
AnProjectionOperation.ProjectionOperationBuilder
that is used for SpEL expression based projections.static class
Builder forProjectionOperation
s on a field.Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation
FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation
-
Constructor Summary
ConstructorDescriptionCreates a new emptyProjectionOperation
.ProjectionOperation
(Class<?> type) Creates a newProjectionOperation
including all top level fields of the giventype
.ProjectionOperation
(Fields fields) Creates a newProjectionOperation
including the givenFields
. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newProjectionOperation.ProjectionOperationBuilder
to define a projection for the field with the given name.and
(AggregationExpression expression) andArrayOf
(Object... values) Includes the given values (field references
,expression
, plain values) as an array.andExclude
(String... fieldNames) Excludes the given fields from the projection.andExpression
(String expression, Object... params) andInclude
(String... fieldNames) Includes the given fields into the projection.andInclude
(Fields fields) Includes the given fields into the projection.Includes the currentProjectionOperation
as an array with given name.Returns the fields exposed by theAggregationOperation
.Return the MongoDB operator that is used for thisAggregationOperation
.boolean
org.bson.Document
toDocument
(AggregationOperationContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.mongodb.core.aggregation.AggregationOperation
toPipelineStages
-
Constructor Details
-
ProjectionOperation
public ProjectionOperation()Creates a new emptyProjectionOperation
. -
ProjectionOperation
Creates a newProjectionOperation
including the givenFields
.- Parameters:
fields
- must not be null.
-
ProjectionOperation
Creates a newProjectionOperation
including all top level fields of the giventype
.- Parameters:
type
- must not be null.- Since:
- 2.2
-
-
Method Details
-
and
Creates a newProjectionOperation.ProjectionOperationBuilder
to define a projection for the field with the given name.- Parameters:
name
- must not be null or empty.- Returns:
-
andExpression
public ProjectionOperation.ExpressionProjectionOperationBuilder andExpression(String expression, Object... params) -
and
-
andExclude
Excludes the given fields from the projection.- Parameters:
fieldNames
- must not be null.- Returns:
-
andInclude
Includes the given fields into the projection.- Parameters:
fieldNames
- must not be null.- Returns:
-
andInclude
Includes the given fields into the projection.- Parameters:
fields
- must not be null.- Returns:
-
asArray
Includes the currentProjectionOperation
as an array with given name.
If you want to specify array values directly useandArrayOf(Object...)
.- Parameters:
name
- the target property name.- Returns:
- new instance of
ProjectionOperation
. - Since:
- 2.2
-
andArrayOf
Includes the given values (field references
,expression
, plain values) as an array.
The target property name needs to be set viaProjectionOperation.ArrayProjectionOperationBuilder.as(String)
.- Parameters:
values
- must not be null.- Returns:
- new instance of
ProjectionOperation.ArrayProjectionOperationBuilder
. - Throws:
IllegalArgumentException
- if the required argument it null.- Since:
- 2.2
-
getFields
Description copied from interface:FieldsExposingAggregationOperation
Returns the fields exposed by theAggregationOperation
.- Specified by:
getFields
in interfaceFieldsExposingAggregationOperation
- Returns:
- will never be null.
-
inheritsFields
public boolean inheritsFields()- Specified by:
inheritsFields
in interfaceFieldsExposingAggregationOperation
- Returns:
- true to conditionally inherit fields from previous operations.
-
toDocument
Description copied from interface:AggregationOperation
- Specified by:
toDocument
in interfaceAggregationOperation
- Parameters:
context
- theAggregationOperationContext
to operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperation
Return the MongoDB operator that is used for thisAggregationOperation
. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperator
in interfaceAggregationOperation
- Returns:
- the operator used for this
AggregationOperation
.
-