You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/core/timeseries/timeseries-migrate-data-into-timeseries-collection.txt
+28-45Lines changed: 28 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -17,39 +17,16 @@ Migrate Data into a Time Series Collection
17
17
18
18
To migrate data from an existing collection into a :ref:`time series
19
19
collection <manual-timeseries-collection>`, use an :pipeline:`$out`
20
-
stage in your aggregation pipeline. If your documents do not have a
21
-
suitable metadata field, use a :pipeline:`$addFields` stage before
22
-
the :pipeline:`$out` stage to add one.
20
+
stage in your aggregation pipeline.
23
21
24
22
Migrate Data to a Time Series Collection
25
23
----------------------------------------
26
24
27
25
.. procedure::
28
26
29
-
.. step:: Create a new time series collection
30
-
31
-
Create a new :ref:`time series collection <manual-timeseries-collection>`
32
-
by issuing the following command in the :binary:`~bin.mongosh`, changing the ``timeField``, ``metaField``, and ``granularity`` values as needed to match the data you're migrating:
33
-
34
-
.. code-block:: javascript
35
-
36
-
db.createCollection(
37
-
"weathernew", {
38
-
timeseries: {
39
-
timeField: "ts",
40
-
metaField: "metaData",
41
-
granularity: "hours"
42
-
}
43
-
}
44
-
)
45
-
46
-
For detailed information on creating a new time series collection,
47
-
see :ref:`Create and Query a Time Series Collection
48
-
<timeseries-create-query-procedures>`.
49
-
50
-
.. step:: (Optional) Transform your data and specify a metadata field
27
+
.. step:: (Optional) Transform your data to create a metadata field if one doesn't exist. This field is not required.
51
28
52
-
If your original collection doesn't have a metadata field, use the :pipeline:`$addFields` aggregation stage to add it. For the example in this procedure, documents require a ``metaData`` field.
29
+
If the original collection doesn't have a metadata field, use the :pipeline:`$addFields` aggregation stage to add it.
53
30
54
31
Consider a collection with weather data that uses the format:
55
32
@@ -89,9 +66,9 @@ Migrate Data to a Time Series Collection
89
66
"estimatedWaterDepth" : 999 }
90
67
}
91
68
92
-
The following pipeline stages add a ``metaData`` field as
93
-
specified in Step 1 and use :pipeline:`$project` to include or
94
-
exclude the remaining fields in the document:
69
+
The following pipeline stages add a ``metaData`` field and use
70
+
:pipeline:`$project` to include or exclude the remaining fields in
71
+
the document:
95
72
96
73
.. code-block:: javascript
97
74
@@ -122,10 +99,9 @@ Migrate Data to a Time Series Collection
122
99
}
123
100
}
124
101
125
-
.. step:: Run the aggregation pipeline with :pipeline:`$out` as the
126
-
final stage
102
+
.. step:: Use the timeseries option with the $out aggregation stage
127
103
128
-
The example below uses the :method:`db.collection.aggregate` helper method:
104
+
The example below uses the :method:`db.collection.aggregate` helper method. For the aggregation stage syntax, see :pipeline:`$out`. For a full explanation of the time series options, see the :ref:`Time Series Field Reference <time-series-fields>`.
129
105
130
106
.. code-block:: javascript
131
107
@@ -157,7 +133,14 @@ Migrate Data to a Time Series Collection
0 commit comments