Skip to content

Commit 5cf205d

Browse files
(DOCSP-18900): Clear up confusing time series example (#108)
1 parent 6a9ff93 commit 5cf205d

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

@@ -162,57 +159,69 @@ Insert Measurements into a Time Series Collection
162159
Each document you insert should contain a single measurement. To insert
163160
multiple documents at once, issue the following command:
164161

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

217226
To insert a single document, use the :method:`db.collection.insertOne()`
218227
method.
@@ -223,7 +232,7 @@ Query a Time Series Collection
223232
To retrieve one document from a time series collection, issue the
224233
following command:
225234

226-
.. code-block:: javescript
235+
.. code-block:: javascript
227236

228237
db.weather.findOne({
229238
"timestamp": ISODate("2021-05-18T00:00:00.000Z")
@@ -235,9 +244,9 @@ Run Aggregations on a Time Series Collection
235244
For additional query functionality, use the :ref:`aggregation framework
236245
<aggregation-framework>`:
237246

238-
.. code-block:: javescript
247+
.. code-block:: javascript
239248

240-
db.weather.aggregate([
249+
db.weather.aggregate( [
241250
{
242251
$project: {
243252
date: {
@@ -258,13 +267,13 @@ For additional query functionality, use the :ref:`aggregation framework
258267
avgTmp: { $avg: "$temp" }
259268
}
260269
}
261-
])
270+
] )
262271

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
264273
measurement and then returns the average of all temperature measurements
265274
that day:
266275

267-
.. code-block:: javescript
276+
.. code-block:: javascript
268277

269278
{
270279
"_id" : {
@@ -301,7 +310,7 @@ To determine if a collection is of type time series, use the
301310

302311
If the collection is a time series collection, it returns this:
303312

304-
.. code-block:: javascript
313+
.. code-block:: none
305314

306315
{
307316
cursor: {
@@ -360,7 +369,7 @@ collection was created. For example, to change the compression algorithm
360369
to ``snappy`` for a new ``weather`` collection, add the following
361370
option:
362371

363-
.. code-block:: javescript
372+
.. code-block:: javascript
364373

365374
db.createCollection(
366375
"weather",

0 commit comments

Comments
 (0)