Skip to content

Commit ad33e9f

Browse files
(DOCSP-18900): Clear up confusing time series example (#108)
1 parent f7a2e83 commit ad33e9f

File tree

1 file changed

+73
-64
lines changed

1 file changed

+73
-64
lines changed

source/core/timeseries-collections.txt

Lines changed: 73 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,14 @@ command:
6565

6666
.. code-block:: javascript
6767

68-
db.createCollection("weather", { timeseries: { timeField: "timestamp" } } )
69-
7068
db.createCollection(
71-
"weather24h",
69+
"weather",
7270
{
7371
timeseries: {
7472
timeField: "timestamp",
7573
metaField: "metadata",
7674
granularity: "hours"
77-
},
78-
expireAfterSeconds: 86400
75+
}
7976
}
8077
)
8178

@@ -139,57 +136,69 @@ Insert Measurements into a Time Series Collection
139136
Each document you insert should contain a single measurement. To insert
140137
multiple documents at once, issue the following command:
141138

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+
] )
193202

194203
To insert a single document, use the :method:`db.collection.insertOne()`
195204
method.
@@ -200,7 +209,7 @@ Query a Time Series Collection
200209
To retrieve one document from a time series collection, issue the
201210
following command:
202211

203-
.. code-block:: javescript
212+
.. code-block:: javascript
204213

205214
db.weather.findOne({
206215
"timestamp": ISODate("2021-05-18T00:00:00.000Z")
@@ -212,9 +221,9 @@ Run Aggregations on a Time Series Collection
212221
For additional query functionality, use the :ref:`aggregation framework
213222
<aggregation-framework>`:
214223

215-
.. code-block:: javescript
224+
.. code-block:: javascript
216225

217-
db.weather.aggregate([
226+
db.weather.aggregate( [
218227
{
219228
$project: {
220229
date: {
@@ -235,13 +244,13 @@ For additional query functionality, use the :ref:`aggregation framework
235244
avgTmp: { $avg: "$temp" }
236245
}
237246
}
238-
])
247+
] )
239248

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
241250
measurement and then returns the average of all temperature measurements
242251
that day:
243252

244-
.. code-block:: javescript
253+
.. code-block:: javascript
245254

246255
{
247256
"_id" : {
@@ -278,7 +287,7 @@ To determine if a collection is of type time series, use the
278287

279288
If the collection is a time series collection, it returns this:
280289

281-
.. code-block:: javascript
290+
.. code-block:: none
282291

283292
{
284293
cursor: {
@@ -337,7 +346,7 @@ collection was created. For example, to change the compression algorithm
337346
to ``snappy`` for a new ``weather`` collection, add the following
338347
option:
339348

340-
.. code-block:: javescript
349+
.. code-block:: javascript
341350

342351
db.createCollection(
343352
"weather",

0 commit comments

Comments
 (0)