Class MergeOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.MergeOperation
- All Implemented Interfaces:
AggregationOperation
,FieldsExposingAggregationOperation
,FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation
public class MergeOperation
extends Object
implements FieldsExposingAggregationOperation, FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation
Encapsulates the
$merge
-operation.
We recommend to use the builder
via builder()
instead of
creating instances of this class directly.
- Since:
- 3.0
- Author:
- Christoph Strobl
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder API to construct aMergeOperation
.static class
Value Object representing theinto
field of a$merge
aggregation stage.static class
Value object representing the unique id used during the merge operation to identify duplicates in the target collection.static class
Value Object specifying how to deal with a result document that do not match an existing document in the collection based on the fields of theon
property describing the unique identifier.static class
Value Object specifying how to deal with a result document that matches an existing document in the collection based on the fields of theon
property describing the unique identifier.Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation
FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation
-
Constructor Summary
ConstructorDescriptionMergeOperation
(MergeOperation.MergeOperationTarget into, MergeOperation.UniqueMergeId on, VariableOperators.Let let, MergeOperation.WhenDocumentsMatch whenMatched, MergeOperation.WhenDocumentsDontMatch whenNotMatched) Create new instance ofMergeOperation
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Access thebuilder API
to create a new instance ofMergeOperation
.Returns the fields exposed by theAggregationOperation
.Return the MongoDB operator that is used for thisAggregationOperation
.boolean
static MergeOperation
Simplified form to apply all default options for$merge
(including writing to a collection in the same database).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
-
MergeOperation
public MergeOperation(MergeOperation.MergeOperationTarget into, MergeOperation.UniqueMergeId on, @Nullable VariableOperators.Let let, @Nullable MergeOperation.WhenDocumentsMatch whenMatched, @Nullable MergeOperation.WhenDocumentsDontMatch whenNotMatched) Create new instance ofMergeOperation
.- Parameters:
into
- the target (collection and database)on
- the unique identifier. Can be null.let
- exposed variables forMergeOperation.WhenDocumentsMatch.updateWith(Aggregation)
. Can be null.whenMatched
- behavior if a result document matches an existing one in the target collection. Can be null.whenNotMatched
- behavior if a result document does not match an existing one in the target collection. Can be null.
-
-
Method Details
-
mergeInto
Simplified form to apply all default options for$merge
(including writing to a collection in the same database).- Parameters:
collection
- the output collection within the same database.- Returns:
- new instance of
MergeOperation
.
-
builder
Access thebuilder API
to create a new instance ofMergeOperation
.- Returns:
- new instance of
MergeOperation.MergeOperationBuilder
.
-
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
.
-
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
- Specified by:
inheritsFields
in interfaceFieldsExposingAggregationOperation.InheritsFieldsAggregationOperation
- Returns:
- true to conditionally inherit fields from previous operations.
-