Class ReplaceRoot

java.lang.Object
dev.morphia.aggregation.stages.Stage
dev.morphia.aggregation.stages.ReplaceRoot

public class ReplaceRoot extends Stage
Replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field.
  • Method Details

    • replaceRoot

      public static ReplaceRoot replaceRoot()
      Creates a new stage
      Returns:
      the new stage
      Since:
      2.2
      MongoDB documentation
      Aggregration Pipeline Stage: $replaceRoot
      Since server release
      3.4
    • replaceRoot

      public static ReplaceRoot replaceRoot(Object 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
    • field

      public ReplaceRoot field(String name, Expression expression)
      Adds a new field
      Parameters:
      name - the field name
      expression - the value expression
      Returns:
      this