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
  • Return the MongoDB operator that is used for this AggregationOperation .
    mapFieldsTo ( Class <?> domainType)
    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.
    pipeline ( AggregationOperation ... aggregationStages)
    Set the aggregation pipeline stages to apply to the specified collection.
    Set the AggregationPipeline to apply to the specified collection.
    org.bson.Document
    Turns the AggregationOperation into a Document by using the given AggregationOperationContext .
    unionWith ( String collection)
    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

    public static UnionWithOperation unionWith ( String collection)
    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

    public UnionWithOperation pipeline ( List < AggregationOperation > aggregationStages)
    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

    public UnionWithOperation pipeline ( AggregationOperation ... aggregationStages)
    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

    public UnionWithOperation mapFieldsTo ( Class <?> domainType)
    Set domain type used for field name mapping of property references used by the AggregationPipeline . Remember to also use a TypedAggregation in the outer pipeline.
    If not set, field names used within pipeline operations are taken as is.
    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

    public org.bson.Document toDocument ( AggregationOperationContext context)
    Description copied from interface: AggregationOperation
    Turns the AggregationOperation into a Document by using the given AggregationOperationContext .
    Specified by:
    toDocument in interface AggregationOperation
    Parameters:
    context - the AggregationOperationContext to operate within. Must not be null.
    Returns:
    the Document

    getOperator

    public String getOperator ()
    Description copied from interface: AggregationOperation
    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 .