Package dev.morphia.aggregation.stages
Class ReplaceWith
java.lang.Object
dev.morphia.aggregation.stages.Stage
dev.morphia.aggregation.stages.ReplaceWith
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.
-
Method Summary
Modifier and TypeMethodDescriptionAdds a new fieldstatic ReplaceWith
Creates a new stagestatic ReplaceWith
replaceWith
(Object expression) Creates a new stage to replace the root with the given expression.
-
Method Details
-
replaceWith
Creates a new stage- Returns:
- the new stage
- Since:
- 2.2
- MongoDB documentation
- Aggregration Pipeline Stage: $replaceWith
- Since server release
- 4.2
-
replaceWith
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
Adds a new field- Parameters:
name
- the field nameexpression
- the value expression- Returns:
- this
-