Skip to content

Commit 6d5abdd

Browse files
authored
DOCS 16485 query time series meta fields (#5542) (#6302)
* 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 9c8ec72 commit 6d5abdd

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

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

+53
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,56 @@ Round Numeric Data to Few Decimal Places
212212
Round numeric data to the precision required for your application.
213213
Rounding numeric data to fewer decimal places improves the compression
214214
ratio.
215+
216+
Optimize Query Performance
217+
--------------------------
218+
219+
Query metaFields on Sub-Fields
220+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221+
222+
MongoDB reorders the metaFields of time-series collections, which may
223+
cause servers to store data in a different field order than
224+
applications. If metaFields are objects, queries on entire metaFields
225+
may produce inconsistent results because metaField order may vary
226+
between servers and applications. To optimize queries on time-series
227+
metaFields, query timeseries metaFields on scalar sub-fields rather than
228+
entire metaFields.
229+
230+
The following example creates a time series collection:
231+
232+
.. code-block:: javascript
233+
234+
db.weather.insertMany( [
235+
{
236+
"metaField": { "sensorId": 5578, "type": "temperature" },
237+
"timestamp": ISODate( "2021-05-18T00:00:00.000Z" ),
238+
"temp": 12
239+
},
240+
{
241+
"metaField": { "sensorId": 5578, "type": "temperature" },
242+
"timestamp": ISODate( "2021-05-18T04:00:00.000Z" ),
243+
"temp": 11
244+
}
245+
] )
246+
247+
The following query on the ``sensorId`` and ``type`` scalar sub-fields
248+
returns the first document that matches the query criteria:
249+
250+
.. code-block:: javascript
251+
252+
db.weather.findOne( {
253+
"metaField.sensorId": 5578,
254+
"metaField.type": "temperature"
255+
} )
256+
257+
Example output:
258+
259+
.. code-block:: javascript
260+
:copyable: false
261+
262+
{
263+
_id: ObjectId("6572371964eb5ad43054d572"),
264+
metaField: { sensorId: 5578, type: 'temperature' },
265+
timestamp: ISODate( "2021-05-18T00:00:00.000Z" ),
266+
temp: 12
267+
}

source/core/timeseries/timeseries-procedures.txt

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ Example output:
204204
_id: ObjectId("62f11bbf1e52f124b84479ad")
205205
}
206206

207+
For more information on time series queries, see
208+
:ref:`tsc-best-practice-optimize-query-performance`.
209+
207210
Run Aggregations on a Time Series Collection
208211
--------------------------------------------
209212

0 commit comments

Comments
 (0)