Skip to content

Commit 2cf2be9

Browse files
Docsp 32680 time series migration using out (#4794)
* Updated to reflect correct syntax for to time series collections * Rendering fix * Rendering fixes * Metadata field is optional * syntax fixes * Empty rebuild * PR comments * External PR feedback * External PR feedback * External PR feedback * Fixed location of metadata field * External feedback
1 parent 4c7b4c2 commit 2cf2be9

File tree

1 file changed

+28
-45
lines changed

1 file changed

+28
-45
lines changed

source/core/timeseries/timeseries-migrate-data-into-timeseries-collection.txt

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,16 @@ Migrate Data into a Time Series Collection
1717

1818
To migrate data from an existing collection into a :ref:`time series
1919
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.
2321

2422
Migrate Data to a Time Series Collection
2523
----------------------------------------
2624

2725
.. procedure::
2826

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.
5128

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.
5330

5431
Consider a collection with weather data that uses the format:
5532

@@ -89,9 +66,9 @@ Migrate Data to a Time Series Collection
8966
"estimatedWaterDepth" : 999 }
9067
}
9168

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:
9572

9673
.. code-block:: javascript
9774

@@ -122,10 +99,9 @@ Migrate Data to a Time Series Collection
12299
}
123100
}
124101

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
127103

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>`.
129105

130106
.. code-block:: javascript
131107

@@ -157,7 +133,14 @@ Migrate Data to a Time Series Collection
157133
precipitationEstimatedObservation: 1
158134
}
159135
}, {
160-
$out: "weathernew"
136+
$out: {
137+
db: "mydatabase",
138+
coll: "weathernew",
139+
timeseries: {
140+
timeField: "ts",
141+
metaField: "metaData"
142+
}
143+
}
161144
}
162145
])
163146

@@ -170,6 +153,17 @@ collection below:
170153
{
171154
"_id" : ObjectId("5553a998e4b02cf7151190b8"),
172155
"ts" : ISODate("1984-03-05T13:00:00Z"),
156+
"metaData" : {
157+
"st" : "x+47600-047900",
158+
"position" : {
159+
"type" : "Point",
160+
"coordinates" : [ -47.9, 47.6 ]
161+
},
162+
"elevation" : 9999,
163+
"callLetters" : "VCSZ",
164+
"qualityControlProcess" : "V020",
165+
"type" : "FM-13"
166+
},
173167
"dataSource" : "4",
174168
"airTemperature" : { "value" : -3.1, "quality" : "1" },
175169
"dewPoint" : { "value" : 999.9, "quality" : "9" },
@@ -188,18 +182,7 @@ collection below:
188182
"cavok" : "N"
189183
},
190184
"sections" : [ "AG1" ],
191-
"precipitationEstimatedObservation" : { "discrepancy" : "2", "estimatedWaterDepth" : 999 },
192-
"metaData" : {
193-
"st" : "x+47600-047900",
194-
"position" : {
195-
"type" : "Point",
196-
"coordinates" : [ -47.9, 47.6 ]
197-
},
198-
"elevation" : 9999,
199-
"callLetters" : "VCSZ",
200-
"qualityControlProcess" : "V020",
201-
"type" : "FM-13"
202-
}
185+
"precipitationEstimatedObservation" : { "discrepancy" : "2", "estimatedWaterDepth" : 999 }
203186
}
204187

205188
If your original collection had secondary indexes, manually recreate

0 commit comments

Comments
 (0)