Skip to content

Commit 47dc830

Browse files
authored
(DOCSP-6955) Add "Convert Field Data Types" page directly to master (#263)
Review on https://github.com/10gen/docs-charts/pull/260 * Structure, WIP * WIP * WIP * WIP * WIP * Ready for internal review * Edit example * Changes based on review * Typo * Table to simplified list * Release notes date updated * Changes based on reviews * Word choice: higher to later
1 parent 7390ec1 commit 47dc830

File tree

5 files changed

+132
-3
lines changed

5 files changed

+132
-3
lines changed

source/build-charts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Create a Chart
2727
:titlesonly:
2828

2929
/view-export-chart-data
30+
/convert-field-data-types
3031
/encoding-channels
3132
/multi-series-charts
3233
/filter-documents
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
.. _convert-field-data-types:
2+
3+
========================
4+
Convert Field Data Types
5+
========================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
You can convert the data type of the fields returned from your data
16+
source in the Chart Builder to a different data type. For example, you
17+
can convert numbers stored as strings to numbers, convert dates stored
18+
as strings or Unix timestamps to dates, or treat ObjectId fields as
19+
dates.
20+
21+
Requirements & Limitations
22+
--------------------------
23+
24+
- Your deployment must use MongoDB 4.0 or later.
25+
26+
- You cannot convert GeoJSON fields.
27+
28+
- You cannot convert arrays nested more than one level deep.
29+
30+
Convert a Field's Data Type
31+
---------------------------
32+
33+
To convert a field's data type, click on that field and select
34+
:guilabel:`Convert type` from the :guilabel:`Ellipses (...)` menu.
35+
36+
.. figure:: /images/charts/convert-field-data-type.png
37+
:figwidth: 25%
38+
:alt: To change a field's data type, click on that field and select "Convert type" from the ellipses menu.
39+
40+
|charts| supports converting data into the following types:
41+
42+
.. list-table::
43+
:header-rows: 1
44+
:widths: 50 50
45+
46+
* - Label
47+
- BSON Type
48+
49+
* - :guilabel:`String`
50+
- :manual:`String </reference/operator/aggregation/convert/#convert-to-string>`
51+
52+
* - :guilabel:`Date`
53+
- :manual:`Date </reference/operator/aggregation/convert/#convert-to-date>`
54+
55+
* - :guilabel:`Number`
56+
- :manual:`Double </reference/operator/aggregation/convert/#convert-to-double>`
57+
58+
* - :guilabel:`Boolean`
59+
- :manual:`Bool </reference/operator/aggregation/convert/#convert-to-bool>`
60+
61+
Data types are converted by an
62+
:manual:`aggregation pipeline </core/aggregation-pipeline>`.
63+
For each type conversion you select, you can find the underlying
64+
aggregation stage by
65+
:ref:`viewing your aggregation pipeline <view-aggregation-pipeline>`.
66+
67+
To see the effects of your conversion on a sample document,
68+
:ref:`view a sample source document <view-source-documents>`.
69+
70+
Your conversions are saved with your chart definition.
71+
72+
Convert Data Types in an Array
73+
------------------------------
74+
75+
You can convert arrays of primitive data and fields of primitive data
76+
from arrays of documents. Each item in the array is converted to the
77+
new type. However, if the conversion is invalid or if the original
78+
value of the item is ``null``, the item converts to ``null``. You
79+
cannot convert arrays nested more than one level deep.
80+
81+
.. example::
82+
83+
You have an array of strings:
84+
85+
.. code-block:: javascript
86+
:copyable: false
87+
88+
["1", "fish", "42"]
89+
90+
Applying the :guilabel:`Number` data type conversion returns the
91+
following array:
92+
93+
.. code-block:: javascript
94+
:copyable: false
95+
96+
[1, null, 45]
97+
98+
.. example::
99+
100+
You have an array of documents with fields ``foo`` and ``bar``:
101+
102+
.. code-block:: javascript
103+
:copyable: false
104+
105+
[{foo: "1", bar: "2"}, {foo: "fish", bar: "tacos"}, {foo: "45",
106+
bar: "46"}]
107+
108+
Applying the :guilabel:`Number` data type conversion to the ``foo``
109+
field returns the following array of documents:
110+
111+
.. code-block:: javascript
112+
:copyable: false
113+
114+
[{foo: 1, bar: "2"}, {foo: null, bar: "tacos"}, {foo: 45, bar:
115+
"46"}]
116+
117+
Revert a Field's Data Type Conversion
118+
-------------------------------------
119+
120+
A converted field's icon reflects the new data type and turns green.
121+
To remove a conversion and return the field to its original data type,
122+
select :guilabel:`Auto Detect` from the :guilabel:`Ellipses (...)`
123+
:icon-fa5:`arrow-right` :guilabel:`Convert Type` menu.
124+
125+
.. figure:: /images/charts/converted-field-icon-example.png
126+
:figwidth: 70%
127+
:alt: A field converted to a string will show a green "A" symbol to indicate its new status.
61.1 KB
Loading
82.9 KB
Loading

source/release-notes.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Release Notes
1313
|charts| on |service| v1.7.0
1414
----------------------------
1515

16-
*Released October 1, 2019*
16+
*Released October 2, 2019*
1717

1818
Improvements in this release:
1919

@@ -27,8 +27,9 @@ Improvements in this release:
2727
- :guilabel:`Get Chart Data` to see the data used on the chart and
2828
export to CSV or JSON.
2929

30-
- Adds the ability to change the data type of fields while building a
31-
chart, when using MongoDB 4.0 or higher.
30+
- Adds the ability to
31+
:ref:`change the data type of fields <convert-field-data-types>`
32+
while building a chart, when using MongoDB 4.0 or later.
3233

3334
- Charts can now be placed across the full width of a dashboard on a
3435
large monitor.

0 commit comments

Comments
 (0)