implements
AggregationOperation
The
$unionWith
aggregation
stage (available since MongoDB 4.4) performs a union of two collections by combining pipeline results, potentially
containing duplicates, into a single result set that is handed over to the next stage.
In order to remove duplicates it is possible to append a
GroupOperation
right after
UnionWithOperation
.
If the
UnionWithOperation
uses a
pipeline
to process documents, field names within the pipeline will be treated as is. In order to map domain type property
names to actual field names (considering potential
Field
annotations) make sure the enclosing aggregation is a
TypedAggregation
and provide the target type for the
$unionWith
stage via
mapFieldsTo(Class)
.
Since:
Author:
Christoph Strobl
See Also:
Aggregation Pipeline Stage:
$unionWith
Set domain type used for field name mapping of property references used by the
AggregationPipeline
.
Set the aggregation pipeline stages to apply to the specified collection.
Set the aggregation pipeline stages to apply to the specified collection.
org.bson.Document
Set the name of the collection from which pipeline results should be included in the result set.
The collection name is used to set the
coll
parameter of
$unionWith
.
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
unionWith
Set the name of the collection from which pipeline results should be included in the result set.
The collection name is used to set the
coll
parameter of
$unionWith
.
Parameters:
collection
- the MongoDB collection name. Must not be null.
Returns:
new instance of
UnionWithOperation
.
Throws:
IllegalArgumentException
- if the required argument is null.
pipeline
Set the
AggregationPipeline
to apply to the specified collection. The pipeline corresponds to the optional
pipeline
field of the
$unionWith
aggregation stage and is used to compute the documents going into
the result set.
Parameters:
pipeline
- the
AggregationPipeline
that computes the documents. Must not be null.
Returns:
new instance of
UnionWithOperation
.
Throws:
IllegalArgumentException
- if the required argument is null.
pipeline
Set the aggregation pipeline stages to apply to the specified collection. The pipeline corresponds to the optional
pipeline
field of the
$unionWith
aggregation stage and is used to compute the documents going into
the result set.
Parameters:
aggregationStages
- the aggregation pipeline stages that compute the documents. Must not be null.
Returns:
new instance of
UnionWithOperation
.
Throws:
IllegalArgumentException
- if the required argument is null.
pipeline
Set the aggregation pipeline stages to apply to the specified collection. The pipeline corresponds to the optional
pipeline
field of the
$unionWith
aggregation stage and is used to compute the documents going into
the result set.
Parameters:
aggregationStages
- the aggregation pipeline stages that compute the documents. Must not be null.
Returns:
new instance of
UnionWithOperation
.
Throws:
IllegalArgumentException
- if the required argument is null.
mapFieldsTo
Parameters:
domainType
- the domain type to map field names used in pipeline operations to. Must not be null.
Returns:
new instance of
UnionWithOperation
.
Throws:
IllegalArgumentException
- if the required argument is null.
toDocument
Specified by:
toDocument
in interface
AggregationOperation
Parameters:
context
- the
AggregationOperationContext
to operate within. Must not be null.
Returns:
the Document
getOperator
Return the MongoDB operator that is used for this
AggregationOperation
. Aggregation operations should
implement this method to avoid document rendering.
Specified by:
getOperator
in interface
AggregationOperation
Returns:
the operator used for this
AggregationOperation
.