$replaceAll

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: String aggregation expressions

What it does

Replaces all occurrences of a substring.

Syntax

{$replaceAll: { input, find, replacement }}

Use case

Remove formatting separators.

$replaceAll: practical example
{ $project: { clean: { $replaceAll: { input: "$phone", find: "-", replacement: "" } } } }
💡 Explanation Replaces all occurrences of a substring. When to use it Remove formatting separators.
Key Takeaways
  • Replaces all occurrences of a substring.
  • Typical use: Remove formatting separators.