|
| 1 | +.. _rm-timeseries: |
| 2 | + |
| 3 | +================================== |
| 4 | +Configure a Time Series Collection |
| 5 | +================================== |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +You can configure mapping rules to migrate a table that contains a |
| 14 | +datetime column to a :ref:`time series collection <manual-timeseries-collection>`. |
| 15 | +Time series collections efficiently store time series data. In time |
| 16 | +series collections, writes are organized so that data from the same |
| 17 | +source is stored alongside other data points from a similar point in time. |
| 18 | + |
| 19 | +About this Task |
| 20 | +--------------- |
| 21 | + |
| 22 | +- You can use :ref:`field customizations <rm-field-customizations>` to |
| 23 | + convert string columns to datetime fields in Relational Migrator. |
| 24 | + |
| 25 | +- :abbr:`CDC (Change Data Capture)` jobs that have time series |
| 26 | + configurations do not create the time series collections until the |
| 27 | + CDC job completes. |
| 28 | + |
| 29 | +- Compared to normal collections, storing time series data in time series |
| 30 | + collections improves query efficiency and reduces the disk usage for |
| 31 | + time series data and :term:`secondary indexes <secondary index>`. |
| 32 | + |
| 33 | +- Use cases for time series collections include |
| 34 | + :abbr:`IoT (Internet of Things)`, forecasting, and time based analysis. |
| 35 | + |
| 36 | +Before you Begin |
| 37 | +---------------- |
| 38 | + |
| 39 | +- For full details on each time series field component, see |
| 40 | + :ref:`time-series-fields`. |
| 41 | + |
| 42 | +- If the time series data in your sync job does not require any |
| 43 | + complex transformations you may benefit from migrating your time |
| 44 | + series data as a separate sync job. This can make it easier to |
| 45 | + preload a large time series collection and migrate the rest of your data after the initial job completes. |
| 46 | + |
| 47 | +- If you're migrating large amounts of data, you might want to use |
| 48 | + :ref:`table filters <rm-table-filters>` to divide your sync jobs into |
| 49 | + batches. For example, you might import one year of historical data at |
| 50 | + a time. This allows you to break down a large job into more manageable |
| 51 | + segments. |
| 52 | + |
| 53 | +- If a long-running sync job fails unexpectedly (for example, due to a |
| 54 | + database outage) and is not able to automatically recover, you may |
| 55 | + be able to use :ref:`table filters <rm-table-filters>` to create a |
| 56 | + new sync job that picks up from where the previous one left off. This |
| 57 | + approach lets you avoid having to repeat the entire sync job. |
| 58 | + |
| 59 | +Steps |
| 60 | +----- |
| 61 | + |
| 62 | +.. procedure:: |
| 63 | + :style: connected |
| 64 | + |
| 65 | + .. step:: Select a collection with a datetime field |
| 66 | + |
| 67 | + a. Navigate to the :guilabel:`Mapping` screen. |
| 68 | + #. On the :guilabel:`Schema model` pane under the |
| 69 | + :guilabel:`MongoDB` header, click on a collection that has a |
| 70 | + datetime field. |
| 71 | + |
| 72 | + .. step:: Configure the time series collection |
| 73 | + |
| 74 | + a. On the :guilabel:`Mappings` pane, click the :icon-lg:`Edit` |
| 75 | + :guilabel:`Configure` button. |
| 76 | + #. Select the :guilabel:`Time Series Collection` radio button. |
| 77 | + #. Select a :guilabel:`Time Field`. |
| 78 | + |
| 79 | + ``Time Field`` is the name of the field which contains the |
| 80 | + datetime field in each time series document. Documents in a |
| 81 | + time series collection must have a valid BSON date data type. |
| 82 | + For details on converting a field to a datetime type in |
| 83 | + Relational Migrator, see |
| 84 | + :ref:`field customizations <rm-field-customizations>`. |
| 85 | + |
| 86 | + .. note:: |
| 87 | + |
| 88 | + If you have multiple datetime columns must select a |
| 89 | + single field per timeseries collection. |
| 90 | + |
| 91 | + #. (Optional) Select a :guilabel:`Meta Field` |
| 92 | + |
| 93 | + ``Meta Field`` is the name of the field that contains metadata |
| 94 | + in each time series document. The metadata in the specified |
| 95 | + field is used to label a unique series of |
| 96 | + documents. The metadata should rarely change. |
| 97 | + |
| 98 | + #. Select a :guilabel:`Granularity`. |
| 99 | + |
| 100 | + Specify a ``Granularity`` value that most closely matches |
| 101 | + the time between consecutive incoming timestamps. Setting the correct granularity |
| 102 | + improves performance by optimizing how MongoDB stores data in the |
| 103 | + collection. Possible values are ``seconds``, ``minutes``, and |
| 104 | + ``hours``. |
| 105 | + |
| 106 | + #. (Optional) Select a :guilabel:`Expire After Seconds`. |
| 107 | + |
| 108 | + ``Expire After Seconds`` enables the automatic deletion |
| 109 | + of documents in a time series collection by specifying the |
| 110 | + number of seconds after which documents expire. MongoDB |
| 111 | + deletes expired documents automatically. |
| 112 | + |
| 113 | + #. Click :guilabel:`Save And Close`. |
| 114 | + |
| 115 | + .. note:: |
| 116 | + |
| 117 | + When a collection is configured with a time series field, |
| 118 | + the time series icon :icon-lg:`TimeSeries` displays next to the collection |
| 119 | + name on the :guilabel:`Schema model` pane. |
| 120 | + |
| 121 | +Example |
| 122 | +------- |
| 123 | + |
| 124 | +The following example converts the ``rental_date`` column into a time |
| 125 | +series field in MongoDB: |
| 126 | + |
| 127 | +.. tabs:: |
| 128 | + |
| 129 | + .. tab:: Relational Input |
| 130 | + :tabid: new-document-in |
| 131 | + |
| 132 | + .. list-table:: |
| 133 | + :header-rows: 1 |
| 134 | + |
| 135 | + * - rental_id |
| 136 | + - rental_date |
| 137 | + - inventory_id |
| 138 | + - customer_id |
| 139 | + - return_date |
| 140 | + - staff_id |
| 141 | + - last_updated |
| 142 | + |
| 143 | + * - 1 |
| 144 | + - 2005-05-24 22:53:30 |
| 145 | + - 367 |
| 146 | + - 130 |
| 147 | + - 2005-05-26 22:04:30 |
| 148 | + - 1 |
| 149 | + - 2006-02-15 20:30:53 |
| 150 | + |
| 151 | + .. tab:: MongoDB Output |
| 152 | + :tabid: Embedded-array-out |
| 153 | + |
| 154 | + .. code-block:: javascript |
| 155 | + :copyable: false |
| 156 | + |
| 157 | + { |
| 158 | + rental_date: { |
| 159 | + $date: "2005-05-24T22:53:30.000Z", |
| 160 | + }, |
| 161 | + last_updated: "2006-02-16T01:30:53Z", |
| 162 | + customerId: 130, |
| 163 | + rental_date: { |
| 164 | + $date: "2005-05-26T22:04:30.000Z", |
| 165 | + }, |
| 166 | + _id: { |
| 167 | + $oid: "661597470a883992d56d60d6", |
| 168 | + }, |
| 169 | + inventory_id: 367, |
| 170 | + staff_id: 1, |
| 171 | + rental_id: 1, |
| 172 | + } |
| 173 | + |
| 174 | +Learn More |
| 175 | +---------- |
| 176 | + |
| 177 | +- :manual:`Time Series Best Practices </core/timeseries/timeseries-best-practices>` |
| 178 | +- :ref:`Optimize Time Series Query Performance <tsc-best-practice-optimize-query-performance>` |
| 179 | +- :ref:`timeseries-add-secondary-index` |
| 180 | +- :ref:`time-series-fields` |
0 commit comments