$replaceOne

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

Reference group: String aggregation expressions

What it does

Replaces the first matching substring; matching is case-sensitive.

Syntax

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

Use case

Replace one known token.

$replaceOne: practical example
{ $project: { clean: { $replaceOne: { input: "$phone", find: " ", replacement: "" } } } }
💡 Explanation Replaces the first matching substring; matching is case-sensitive. When to use it Replace one known token.
Key Takeaways
  • Replaces the first matching substring; matching is case-sensitive.
  • Typical use: Replace one known token.