$convert

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

Reference group: Conversion and type inspection

What it does

General conversion with explicit error/null behavior.

Syntax

{$convert: { input, to, onError?, onNull? }}

Use case

Process dirty imports without failing the pipeline.

$convert: practical example
{ $set: { safeQty: { $convert: { input: "$qtyText", to: "int", onError: null, onNull: 0 } } } }
💡 Explanation General conversion with explicit error/null behavior. When to use it Process dirty imports without failing the pipeline.
Key Takeaways
  • General conversion with explicit error/null behavior.
  • Typical use: Process dirty imports without failing the pipeline.