$substrBytes

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

Reference group: String aggregation expressions

What it does

Extracts by byte offsets.

Syntax

{$substrBytes: [string, start, count]}

Use case

Byte-oriented parsing.

Important notes

May split a multibyte character.

$substrBytes: practical example
{ $project: { prefix: { $substrBytes: ["$code", 0, 4] } } }
💡 Explanation Extracts by byte offsets. When to use it Byte-oriented parsing. Caution May split a multibyte character.
Key Takeaways
  • Extracts by byte offsets.
  • Typical use: Byte-oriented parsing.