@@ -65,17 +65,14 @@ command:
65
65
66
66
.. code-block:: javascript
67
67
68
- db.createCollection("weather", { timeseries: { timeField: "timestamp" } } )
69
-
70
68
db.createCollection(
71
- "weather24h ",
69
+ "weather ",
72
70
{
73
71
timeseries: {
74
72
timeField: "timestamp",
75
73
metaField: "metadata",
76
74
granularity: "hours"
77
- },
78
- expireAfterSeconds: 86400
75
+ }
79
76
}
80
77
)
81
78
@@ -139,57 +136,69 @@ Insert Measurements into a Time Series Collection
139
136
Each document you insert should contain a single measurement. To insert
140
137
multiple documents at once, issue the following command:
141
138
142
- .. code-block:: javescript
143
-
144
- db.weather.insertMany([{
145
- "metadata": {"sensorId": 5578, "type": "temperature"},
146
- "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
147
- "temp": 12
148
- }, {
149
- "metadata": {"sensorId": 5578, "type": "temperature"},
150
- "timestamp": ISODate("2021-05-18T04:00:00.000Z"),
151
- "temp": 11
152
- }, {
153
- "metadata": {"sensorId": 5578, "type": "temperature"},
154
- "timestamp": ISODate("2021-05-18T08:00:00.000Z"),
155
- "temp": 11
156
- }, {
157
- "metadata": {"sensorId": 5578, "type": "temperature"},
158
- "timestamp": ISODate("2021-05-18T12:00:00.000Z"),
159
- "temp": 12
160
- }, {
161
- "metadata": {"sensorId": 5578, "type": "temperature"},
162
- "timestamp": ISODate("2021-05-18T16:00:00.000Z"),
163
- "temp": 16
164
- }, {
165
- "metadata": {"sensorId": 5578, "type": "temperature"},
166
- "timestamp": ISODate("2021-05-18T20:00:00.000Z"),
167
- "temp": 15
168
- }, {
169
- "metadata": {"sensorId": 5578, "type": "temperature"},
170
- "timestamp": ISODate("2021-05-19T00:00:00.000Z"),
171
- "temp": 13
172
- }, {
173
- "metadata": {"sensorId": 5578, "type": "temperature"},
174
- "timestamp": ISODate("2021-05-19T04:00:00.000Z"),
175
- "temp": 12
176
- }, {
177
- "metadata": {"sensorId": 5578, "type": "temperature"},
178
- "timestamp": ISODate("2021-05-19T08:00:00.000Z"),
179
- "temp": 11
180
- }, {
181
- "metadata": {"sensorId": 5578, "type": "temperature"},
182
- "timestamp": ISODate("2021-05-19T12:00:00.000Z"),
183
- "temp": 12
184
- }, {
185
- "metadata": {"sensorId": 5578, "type": "temperature"},
186
- "timestamp": ISODate("2021-05-19T16:00:00.000Z"),
187
- "temp": 17
188
- }, {
189
- "metadata": {"sensorId": 5578, "type": "temperature"},
190
- "timestamp": ISODate("2021-05-19T20:00:00.000Z"),
191
- "temp": 12
192
- }])
139
+ .. code-block:: javascript
140
+
141
+ db.weather.insertMany( [
142
+ {
143
+ "metadata": { "sensorId": 5578, "type": "temperature" },
144
+ "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
145
+ "temp": 12
146
+ },
147
+ {
148
+ "metadata": { "sensorId": 5578, "type": "temperature" },
149
+ "timestamp": ISODate("2021-05-18T04:00:00.000Z"),
150
+ "temp": 11
151
+ },
152
+ {
153
+ "metadata": { "sensorId": 5578, "type": "temperature" },
154
+ "timestamp": ISODate("2021-05-18T08:00:00.000Z"),
155
+ "temp": 11
156
+ },
157
+ {
158
+ "metadata": { "sensorId": 5578, "type": "temperature" },
159
+ "timestamp": ISODate("2021-05-18T12:00:00.000Z"),
160
+ "temp": 12
161
+ },
162
+ {
163
+ "metadata": { "sensorId": 5578, "type": "temperature" },
164
+ "timestamp": ISODate("2021-05-18T16:00:00.000Z"),
165
+ "temp": 16
166
+ },
167
+ {
168
+ "metadata": { "sensorId": 5578, "type": "temperature" },
169
+ "timestamp": ISODate("2021-05-18T20:00:00.000Z"),
170
+ "temp": 15
171
+ }, {
172
+ "metadata": { "sensorId": 5578, "type": "temperature" },
173
+ "timestamp": ISODate("2021-05-19T00:00:00.000Z"),
174
+ "temp": 13
175
+ },
176
+ {
177
+ "metadata": { "sensorId": 5578, "type": "temperature" },
178
+ "timestamp": ISODate("2021-05-19T04:00:00.000Z"),
179
+ "temp": 12
180
+ },
181
+ {
182
+ "metadata": { "sensorId": 5578, "type": "temperature" },
183
+ "timestamp": ISODate("2021-05-19T08:00:00.000Z"),
184
+ "temp": 11
185
+ },
186
+ {
187
+ "metadata": { "sensorId": 5578, "type": "temperature" },
188
+ "timestamp": ISODate("2021-05-19T12:00:00.000Z"),
189
+ "temp": 12
190
+ },
191
+ {
192
+ "metadata": { "sensorId": 5578, "type": "temperature" },
193
+ "timestamp": ISODate("2021-05-19T16:00:00.000Z"),
194
+ "temp": 17
195
+ },
196
+ {
197
+ "metadata": { "sensorId": 5578, "type": "temperature" },
198
+ "timestamp": ISODate("2021-05-19T20:00:00.000Z"),
199
+ "temp": 12
200
+ }
201
+ ] )
193
202
194
203
To insert a single document, use the :method:`db.collection.insertOne()`
195
204
method.
@@ -200,7 +209,7 @@ Query a Time Series Collection
200
209
To retrieve one document from a time series collection, issue the
201
210
following command:
202
211
203
- .. code-block:: javescript
212
+ .. code-block:: javascript
204
213
205
214
db.weather.findOne({
206
215
"timestamp": ISODate("2021-05-18T00:00:00.000Z")
@@ -212,9 +221,9 @@ Run Aggregations on a Time Series Collection
212
221
For additional query functionality, use the :ref:`aggregation framework
213
222
<aggregation-framework>`:
214
223
215
- .. code-block:: javescript
224
+ .. code-block:: javascript
216
225
217
- db.weather.aggregate([
226
+ db.weather.aggregate( [
218
227
{
219
228
$project: {
220
229
date: {
@@ -235,13 +244,13 @@ For additional query functionality, use the :ref:`aggregation framework
235
244
avgTmp: { $avg: "$temp" }
236
245
}
237
246
}
238
- ])
247
+ ] )
239
248
240
- The preceeding example groups all documents by the date of the
249
+ The example aggregation pipeline groups all documents by the date of the
241
250
measurement and then returns the average of all temperature measurements
242
251
that day:
243
252
244
- .. code-block:: javescript
253
+ .. code-block:: javascript
245
254
246
255
{
247
256
"_id" : {
@@ -278,7 +287,7 @@ To determine if a collection is of type time series, use the
278
287
279
288
If the collection is a time series collection, it returns this:
280
289
281
- .. code-block:: javascript
290
+ .. code-block:: none
282
291
283
292
{
284
293
cursor: {
@@ -337,7 +346,7 @@ collection was created. For example, to change the compression algorithm
337
346
to ``snappy`` for a new ``weather`` collection, add the following
338
347
option:
339
348
340
- .. code-block:: javescript
349
+ .. code-block:: javascript
341
350
342
351
db.createCollection(
343
352
"weather",
0 commit comments