@@ -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
263263higher, 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+ }
0 commit comments