Skip to content

Commit e1d2806

Browse files
authored
DOCS 16485 query time series meta fields (#5542)
* DOCS-16485 time-series metafield query * DOCS-16485 updating example * DOCS-16485 updating example * DOCS-16485 updating example * DOCS-16485 updating title * DOCS-16485 copy edits * DOCS-16485 tech edits: * DOCS-16485 updating limitations page * DOCS-16485 moving example to limitations page * DOCS-16485 moving example to best practices page and off limitations page * DOCS-16485 fixing wording * DOCS-16485 copy edits * DOCS-16485 copy edits
1 parent e9cd3a2 commit e1d2806

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

source/core/timeseries/timeseries-best-practices.txt

+51-1
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,54 @@ To improve query performance, :ref:`create one or more secondary indexes
261261
<timeseries-add-secondary-index>` on your ``timeField`` and
262262
``metaField`` to support common query patterns. In versions 6.3 and
263263
higher, MongoDB creates a secondary index on the ``timeField`` and
264-
``metaField`` automatically.
264+
``metaField`` automatically.
265+
266+
Query metaFields on Sub-Fields
267+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268+
269+
MongoDB reorders the metaFields of time-series collections, which may
270+
cause servers to store data in a different field order than
271+
applications. If metaFields are objects, queries on entire metaFields
272+
may produce inconsistent results because metaField order may vary
273+
between servers and applications. To optimize queries on time-series
274+
metaFields, query timeseries metaFields on scalar sub-fields rather than
275+
entire metaFields.
276+
277+
The following example creates a time series collection:
278+
279+
.. code-block:: javascript
280+
281+
db.weather.insertMany( [
282+
{
283+
"metaField": { "sensorId": 5578, "type": "temperature" },
284+
"timestamp": ISODate( "2021-05-18T00:00:00.000Z" ),
285+
"temp": 12
286+
},
287+
{
288+
"metaField": { "sensorId": 5578, "type": "temperature" },
289+
"timestamp": ISODate( "2021-05-18T04:00:00.000Z" ),
290+
"temp": 11
291+
}
292+
] )
293+
294+
The following query on the ``sensorId`` and ``type`` scalar sub-fields
295+
returns the first document that matches the query criteria:
296+
297+
.. code-block:: javascript
298+
299+
db.weather.findOne( {
300+
"metaField.sensorId": 5578,
301+
"metaField.type": "temperature"
302+
} )
303+
304+
Example output:
305+
306+
.. code-block:: javascript
307+
:copyable: false
308+
309+
{
310+
_id: ObjectId("6572371964eb5ad43054d572"),
311+
metaField: { sensorId: 5578, type: 'temperature' },
312+
timestamp: ISODate( "2021-05-18T00:00:00.000Z" ),
313+
temp: 12
314+
}

source/core/timeseries/timeseries-procedures.txt

+3
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ Example output:
262262
_id: ObjectId("62f11bbf1e52f124b84479ad")
263263
}
264264

265+
For more information on time series queries, see
266+
:ref:`tsc-best-practice-optimize-query-performance`.
267+
265268
Run Aggregations on a Time Series Collection
266269
--------------------------------------------
267270

0 commit comments

Comments
 (0)