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, Amine Jaoui
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder forarrayprojections.static classAnProjectionOperation.ProjectionOperationBuilderthat is used for SpEL expression based projections.static classBuilder forProjectionOperations on a field.Nested classes/interfaces inherited from interface FieldsExposingAggregationOperation
FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new emptyProjectionOperation.ProjectionOperation(Class<?> type) Creates a newProjectionOperationincluding all top level fields of the giventype.ProjectionOperation(Fields fields) Creates a newProjectionOperationincluding the givenFields. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newProjectionOperation.ProjectionOperationBuilderto 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 currentProjectionOperationas an array with given name.Returns the fields exposed by theAggregationOperation.Return the MongoDB operator that is used for thisAggregationOperation.booleanorg.bson.DocumenttoDocument(AggregationOperationContext context) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AggregationOperation
toPipelineStages
-
Constructor Details
-
ProjectionOperation
public ProjectionOperation()Creates a new emptyProjectionOperation. -
ProjectionOperation
Creates a newProjectionOperationincluding the givenFields.- Parameters:
fields- must not be null.
-
ProjectionOperation
Creates a newProjectionOperationincluding all top level fields of the giventype.- Parameters:
type- must not be null.- Since:
- 2.2
-
-
Method Details
-
and
Creates a newProjectionOperation.ProjectionOperationBuilderto 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 currentProjectionOperationas 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:FieldsExposingAggregationOperationReturns the fields exposed by theAggregationOperation.- Specified by:
getFieldsin interfaceFieldsExposingAggregationOperation- Returns:
- will never be null.
-
inheritsFields
public boolean inheritsFields()- Specified by:
inheritsFieldsin interfaceFieldsExposingAggregationOperation- Returns:
- true to conditionally inherit fields from previous operations.
-
toDocument
Description copied from interface:AggregationOperation- Specified by:
toDocumentin interfaceAggregationOperation- Parameters:
context- theAggregationOperationContextto operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperationReturn the MongoDB operator that is used for thisAggregationOperation. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperatorin interfaceAggregationOperation- Returns:
- the operator used for this
AggregationOperation.
-