Skip to main content

$toString

The $toString operator converts a value to a string, with optional formatting for dates.

Input

  • An array containing one or two values: the value to convert and an optional format string (for dates)

Output

  • The string representation of the input value

Examples

Basic Conversion

{
  "$toString": [
    42
  ]
}
Result: "42"

Date Formatting

{
  "$toString": [
    {
      "$toDate": ["2023-01-15T10:30:00Z"]
    },
    "2006-01-02 15:04:05"
  ]
}
Result: "2023-01-15 10:30:00"

Field Value

{
  "$toString": [
    {
      "$input": "number_value"
    }
  ]
}
Result: The string representation of the number_value field