Module spring.data.mongodb
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
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder API to construct aMergeOperation.static classValue Object representing theintofield of a$mergeaggregation stage.static classValue object representing the unique id used during the merge operation to identify duplicates in the target collection.static classValue Object specifying how to deal with a result document that do not match an existing document in the collection based on the fields of theonproperty describing the unique identifier.static classValue Object specifying how to deal with a result document that matches an existing document in the collection based on the fields of theonproperty describing the unique identifier.Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation
FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation -
Constructor Summary
ConstructorsConstructorDescriptionMergeOperation(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 APIto create a new instance ofMergeOperation.Returns the fields exposed by theAggregationOperation.Return the MongoDB operator that is used for thisAggregationOperation.booleanstatic MergeOperationSimplified form to apply all default options for$merge(including writing to a collection in the same database).org.bson.DocumenttoDocument(AggregationOperationContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 APIto create a new instance ofMergeOperation.- Returns:
- new instance of
MergeOperation.MergeOperationBuilder.
-
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.
-
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- Specified by:
inheritsFieldsin interfaceFieldsExposingAggregationOperation.InheritsFieldsAggregationOperation- Returns:
- true to conditionally inherit fields from previous operations.
-