$replaceRoot / $replaceWith
Reference group: Pipeline stages
What it does
Replaces the current document with another document expression.
Syntax
{$replaceWith: expression}
Use case
Promote a nested object.
$replaceRoot / $replaceWith: practical example
{ $replaceWith: "$profile" }💡 Explanation
Replaces the current document with another document expression.
When to use it
Promote a nested object.
Key Takeaways
- Replaces the current document with another document expression.
- Typical use: Promote a nested object.