$toInt
Reference group: Conversion and type inspection
What it does
Converts compatible values to 32-bit integer.
Syntax
{$toInt: expression}
Use case
Normalize numeric strings.
Important notes
Invalid strings or out-of-range values can fail.
$toInt: practical example
{ $set: { quantityInt: { $toInt: "$quantityText" } } }💡 Explanation
Converts compatible values to 32-bit integer.
When to use it
Normalize numeric strings.
Caution
Invalid strings or out-of-range values can fail.
Key Takeaways
- Converts compatible values to 32-bit integer.
- Typical use: Normalize numeric strings.