Docs Menu
Docs Home
/
Atlas Charts
/ /

Convert Field Data Types

On this page

  • Requirements & Limitations
  • Convert a Field's Data Type
  • Convert Data Types in an Array
  • Revert a Field's Data Type Conversion

You can convert the data type of the fields returned from your data source in the Chart Builder to a different data type. For example, you can convert numbers stored as strings to numbers, convert dates stored as strings or Unix timestamps to dates, or treat ObjectId fields as dates.

  • Your deployment must use MongoDB 4.0 or later.

  • You cannot convert GeoJSON fields.

  • You cannot convert arrays nested more than one level deep.

To convert a field's data type, click on that field and select Convert type from the Ellipsis (...) menu.

To change a field's data type, click on that field and select "Convert type" from the ellipses menu.
click to enlarge

Atlas Charts supports converting data into the following types:

Label
BSON Type
String
String
Date
Number
Boolean

Data types are converted by an aggregation pipeline. For each type conversion you select, you can find the underlying aggregation stage by viewing your aggregation pipeline.

To see the effects of your conversion on a sample document, view a sample source document.

Your conversions are saved with your chart definition.

You can convert arrays of primitive data and fields of primitive data from arrays of documents. Each item in the array is converted to the new type. However, if the conversion is invalid or if the original value of the item is null, the item converts to null. You cannot convert arrays nested more than one level deep.

Example

You have an array of strings:

["1", "fish", "42"]

Applying the Number data type conversion returns the following array:

[1, null, 45]

Example

You have an array of documents with fields foo and bar:

[{foo: "1", bar: "2"}, {foo: "fish", bar: "tacos"}, {foo: "45",
bar: "46"}]

Applying the Number data type conversion to the foo field returns the following array of documents:

[{foo: 1, bar: "2"}, {foo: null, bar: "tacos"}, {foo: 45, bar:
"46"}]

A converted field's icon reflects the new data type and turns green. To remove a conversion and return the field to its original data type, select Auto Detect from the Ellipses (...) Convert Type menu.

A field converted to a string will show a green "A" symbol to indicate its new status.
click to enlarge

Back

Calculate New Data Fields