Class ReplaceWith


  • public class ReplaceWith
    extends Stage
    Replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field. With $replaceWith, you can promote an embedded document to the top-level. You can also specify a new document as the replacement.

    The $replaceWith is an alias for $replaceRoot.

    • Constructor Detail

      • ReplaceWith

        protected ReplaceWith​(dev.morphia.aggregation.expressions.impls.Expression expression)
      • ReplaceWith

        protected ReplaceWith()
    • Method Detail

      • replaceWith

        public static ReplaceWith replaceWith()
        Creates a new stage
        Returns:
        the new stage
        Since:
        2.2
      • replaceWith

        public static ReplaceWith replaceWith​(dev.morphia.aggregation.expressions.impls.Expression expression)
        Creates a new stage to replace the root with the given expression. This expression must evaluate to a document. No further fields can be added to this stage.
        Parameters:
        expression - the document expression
        Returns:
        the new stage
        Since:
        2.2
      • with

        @Deprecated(forRemoval=true)
        public static ReplaceWith with​(dev.morphia.aggregation.expressions.impls.Expression expression)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a new stage to replace the root with the given expression. This expression must evaluate to a document. No further fields can be added to this stage.
        Parameters:
        expression - the document expression
        Returns:
        the new stage
      • field

        public ReplaceWith field​(String name,
                                 dev.morphia.aggregation.expressions.impls.Expression expression)
        Adds a new field
        Parameters:
        name - the field name
        expression - the value expression
        Returns:
        this
      • getDocument

        @MorphiaInternal
        public dev.morphia.aggregation.expressions.impls.DocumentExpression getDocument()
        Returns:
        the expression
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getValue

        @Nullable
        @MorphiaInternal
        public dev.morphia.aggregation.expressions.impls.Expression getValue()
        Returns:
        the expression
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.