Class Merge<M>

  • Type Parameters:
    M - the entity type

    public class Merge<M>
    extends Stage
    Writes the results of the aggregation pipeline to a specified collection. The $merge operator must be the last stage in the pipeline.
    • Constructor Detail

      • Merge

        protected Merge​(Class<M> type)
      • Merge

        protected Merge()
      • Merge

        protected Merge​(String collection)
      • Merge

        protected Merge​(String database,
                        String collection)
    • Method Detail

      • into

        public static <M> Merge<M> into​(Class<M> type)
        Creates a new stage targeting the collection mapped for the given type
        Type Parameters:
        M - the entity type
        Parameters:
        type - the target type
        Returns:
        the new stage
      • into

        public static Merge<?> into​(String collection)
        Creates a new stage targeting the collection
        Parameters:
        collection - the target collection
        Returns:
        the new stage
      • into

        public static Merge<?> into​(String database,
                                    String collection)
        Creates a new stage targeting the database and collection
        Parameters:
        database - the target database
        collection - the target collection
        Returns:
        the new stage
      • getCollection

        public String getCollection()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getDatabase

        public String getDatabase()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getOn

        public List<String> getOn()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getType

        public Class<M> getType()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getVariables

        public Map<String,​Expression> getVariables()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getWhenMatched

        public com.mongodb.client.model.MergeOptions.WhenMatched getWhenMatched()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getWhenMatchedPipeline

        public List<Stage> getWhenMatchedPipeline()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getWhenNotMatched

        public com.mongodb.client.model.MergeOptions.WhenNotMatched getWhenNotMatched()
        Returns:
        the value
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • let

        public Merge<M> let​(String variable,
                            Expression value)
        Specifies a variable accessible for use in the whenMatched pipeline
        Parameters:
        variable - the variable name
        value - the value expression
        Returns:
        this
      • on

        public Merge<M> on​(String field,
                           String... fields)
        Optional. Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an already existing document in the output collection.
        Parameters:
        field - the first field
        fields - the other fields
        Returns:
        this
      • whenMatched

        public Merge<M> whenMatched​(com.mongodb.client.model.MergeOptions.WhenMatched whenMatched)
        Optional. The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s).
        Parameters:
        whenMatched - the behavior
        Returns:
        this
      • whenMatched

        public Merge<M> whenMatched​(List<Stage> pipeline)
        Optional. An aggregation pipeline to update the document in the collection.
        Parameters:
        pipeline - the pipeline
        Returns:
        this
      • whenNotMatched

        public Merge<M> whenNotMatched​(com.mongodb.client.model.MergeOptions.WhenNotMatched whenNotMatched)
        Optional. The behavior of $merge if a result document does not match an existing document in the out collection.
        Parameters:
        whenNotMatched - the behavior
        Returns:
        this