@@ -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
@@ -162,57 +159,69 @@ Insert Measurements into a Time Series Collection
162
159
Each document you insert should contain a single measurement. To insert
163
160
multiple documents at once, issue the following command:
164
161
165
- .. code-block:: javescript
166
-
167
- db.weather.insertMany([{
168
- "metadata": {"sensorId": 5578, "type": "temperature"},
169
- "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
170
- "temp": 12
171
- }, {
172
- "metadata": {"sensorId": 5578, "type": "temperature"},
173
- "timestamp": ISODate("2021-05-18T04:00:00.000Z"),
174
- "temp": 11
175
- }, {
176
- "metadata": {"sensorId": 5578, "type": "temperature"},
177
- "timestamp": ISODate("2021-05-18T08:00:00.000Z"),
178
- "temp": 11
179
- }, {
180
- "metadata": {"sensorId": 5578, "type": "temperature"},
181
- "timestamp": ISODate("2021-05-18T12:00:00.000Z"),
182
- "temp": 12
183
- }, {
184
- "metadata": {"sensorId": 5578, "type": "temperature"},
185
- "timestamp": ISODate("2021-05-18T16:00:00.000Z"),
186
- "temp": 16
187
- }, {
188
- "metadata": {"sensorId": 5578, "type": "temperature"},
189
- "timestamp": ISODate("2021-05-18T20:00:00.000Z"),
190
- "temp": 15
191
- }, {
192
- "metadata": {"sensorId": 5578, "type": "temperature"},
193
- "timestamp": ISODate("2021-05-19T00:00:00.000Z"),
194
- "temp": 13
195
- }, {
196
- "metadata": {"sensorId": 5578, "type": "temperature"},
197
- "timestamp": ISODate("2021-05-19T04:00:00.000Z"),
198
- "temp": 12
199
- }, {
200
- "metadata": {"sensorId": 5578, "type": "temperature"},
201
- "timestamp": ISODate("2021-05-19T08:00:00.000Z"),
202
- "temp": 11
203
- }, {
204
- "metadata": {"sensorId": 5578, "type": "temperature"},
205
- "timestamp": ISODate("2021-05-19T12:00:00.000Z"),
206
- "temp": 12
207
- }, {
208
- "metadata": {"sensorId": 5578, "type": "temperature"},
209
- "timestamp": ISODate("2021-05-19T16:00:00.000Z"),
210
- "temp": 17
211
- }, {
212
- "metadata": {"sensorId": 5578, "type": "temperature"},
213
- "timestamp": ISODate("2021-05-19T20:00:00.000Z"),
214
- "temp": 12
215
- }])
162
+ .. code-block:: javascript
163
+
164
+ db.weather.insertMany( [
165
+ {
166
+ "metadata": { "sensorId": 5578, "type": "temperature" },
167
+ "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
168
+ "temp": 12
169
+ },
170
+ {
171
+ "metadata": { "sensorId": 5578, "type": "temperature" },
172
+ "timestamp": ISODate("2021-05-18T04:00:00.000Z"),
173
+ "temp": 11
174
+ },
175
+ {
176
+ "metadata": { "sensorId": 5578, "type": "temperature" },
177
+ "timestamp": ISODate("2021-05-18T08:00:00.000Z"),
178
+ "temp": 11
179
+ },
180
+ {
181
+ "metadata": { "sensorId": 5578, "type": "temperature" },
182
+ "timestamp": ISODate("2021-05-18T12:00:00.000Z"),
183
+ "temp": 12
184
+ },
185
+ {
186
+ "metadata": { "sensorId": 5578, "type": "temperature" },
187
+ "timestamp": ISODate("2021-05-18T16:00:00.000Z"),
188
+ "temp": 16
189
+ },
190
+ {
191
+ "metadata": { "sensorId": 5578, "type": "temperature" },
192
+ "timestamp": ISODate("2021-05-18T20:00:00.000Z"),
193
+ "temp": 15
194
+ }, {
195
+ "metadata": { "sensorId": 5578, "type": "temperature" },
196
+ "timestamp": ISODate("2021-05-19T00:00:00.000Z"),
197
+ "temp": 13
198
+ },
199
+ {
200
+ "metadata": { "sensorId": 5578, "type": "temperature" },
201
+ "timestamp": ISODate("2021-05-19T04:00:00.000Z"),
202
+ "temp": 12
203
+ },
204
+ {
205
+ "metadata": { "sensorId": 5578, "type": "temperature" },
206
+ "timestamp": ISODate("2021-05-19T08:00:00.000Z"),
207
+ "temp": 11
208
+ },
209
+ {
210
+ "metadata": { "sensorId": 5578, "type": "temperature" },
211
+ "timestamp": ISODate("2021-05-19T12:00:00.000Z"),
212
+ "temp": 12
213
+ },
214
+ {
215
+ "metadata": { "sensorId": 5578, "type": "temperature" },
216
+ "timestamp": ISODate("2021-05-19T16:00:00.000Z"),
217
+ "temp": 17
218
+ },
219
+ {
220
+ "metadata": { "sensorId": 5578, "type": "temperature" },
221
+ "timestamp": ISODate("2021-05-19T20:00:00.000Z"),
222
+ "temp": 12
223
+ }
224
+ ] )
216
225
217
226
To insert a single document, use the :method:`db.collection.insertOne()`
218
227
method.
@@ -223,7 +232,7 @@ Query a Time Series Collection
223
232
To retrieve one document from a time series collection, issue the
224
233
following command:
225
234
226
- .. code-block:: javescript
235
+ .. code-block:: javascript
227
236
228
237
db.weather.findOne({
229
238
"timestamp": ISODate("2021-05-18T00:00:00.000Z")
@@ -235,9 +244,9 @@ Run Aggregations on a Time Series Collection
235
244
For additional query functionality, use the :ref:`aggregation framework
236
245
<aggregation-framework>`:
237
246
238
- .. code-block:: javescript
247
+ .. code-block:: javascript
239
248
240
- db.weather.aggregate([
249
+ db.weather.aggregate( [
241
250
{
242
251
$project: {
243
252
date: {
@@ -258,13 +267,13 @@ For additional query functionality, use the :ref:`aggregation framework
258
267
avgTmp: { $avg: "$temp" }
259
268
}
260
269
}
261
- ])
270
+ ] )
262
271
263
- The preceeding example groups all documents by the date of the
272
+ The example aggregation pipeline groups all documents by the date of the
264
273
measurement and then returns the average of all temperature measurements
265
274
that day:
266
275
267
- .. code-block:: javescript
276
+ .. code-block:: javascript
268
277
269
278
{
270
279
"_id" : {
@@ -301,7 +310,7 @@ To determine if a collection is of type time series, use the
301
310
302
311
If the collection is a time series collection, it returns this:
303
312
304
- .. code-block:: javascript
313
+ .. code-block:: none
305
314
306
315
{
307
316
cursor: {
@@ -360,7 +369,7 @@ collection was created. For example, to change the compression algorithm
360
369
to ``snappy`` for a new ``weather`` collection, add the following
361
370
option:
362
371
363
- .. code-block:: javescript
372
+ .. code-block:: javascript
364
373
365
374
db.createCollection(
366
375
"weather",
0 commit comments