Skip to content

Commit 3ebce89

Browse files
DOCS-15516 Time series range outside 1970-2038 behavior (#2119) (#7914)
* DOCS-15516 Time series range outside 1970-2038 behavior (#2119) * Rebuild * Syntax fix
1 parent 9316ea1 commit 3ebce89

File tree

4 files changed

+56
-72
lines changed

4 files changed

+56
-72
lines changed

source/core/timeseries-collections.txt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,39 @@ When you query time series collections, you operate on one document per
115115
measurement. Queries on time series collections take advantage of the
116116
optimized internal storage format and return results faster.
117117

118+
.. tip::
119+
120+
To improve query performance, you can manually :ref:`add secondary
121+
indexes <timeseries-add-secondary-index>` on measurement fields or
122+
any field in your time series collection.
123+
118124
.. important:: Backward-Incompatible Feature
119125

120126
.. include:: /includes/downgrade-for-timeseries-collections.rst
121127

122128
.. include:: /includes/database-profiler-note.rst
123129

130+
.. _manual-timeseries-internal-index:
131+
124132
Internal Index
125133
``````````````
126134

127135
When you create a time series collection, MongoDB automatically creates
128136
an internal :ref:`clustered index <clustered-collections>` on the time
129-
field. The internal index provides several performance benefits
130-
including improved query efficiency and reduced disk usage. To learn
131-
more about the performance benefits of clustered indexes, see
132-
:ref:`Clustered Collections <clustered-collections>`.
133-
134-
The internal index for a time series collection is not displayed by
135-
:dbcommand:`listIndexes`.
136-
137-
.. tip::
138-
139-
To improve query performance, you can manually :ref:`add secondary
140-
indexes <timeseries-add-secondary-index>` on measurement fields or
141-
any field in your time series collection.
137+
field. This index improves query efficiency and reduces disk
138+
usage. To learn more about the performance benefits of clustered
139+
indexes, see :ref:`Clustered Collections <clustered-collections>`.
140+
141+
The internal index is not listed when you run :dbcommand:`listIndexes`.
142+
143+
.. note::
144+
If you insert a document into a collection with a ``timeField``
145+
value before ``1970-01-01T00:00:00.000Z`` or after
146+
``2038-01-19T03:14:07.000Z``,
147+
MongoDB logs a warning and prevents some query optimizations from
148+
using the internal index. :ref:`Create a secondary index <timeseries-add-secondary-index>`
149+
on the ``timeField`` to regain query performance and resolve the log
150+
warning.
142151

143152
Get Started
144153
-----------

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

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -209,52 +209,7 @@ ratio.
209209
Optimize Query Performance
210210
--------------------------
211211

212-
Query metaFields on Sub-Fields
213-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214-
215-
MongoDB reorders the metaFields of time-series collections, which may
216-
cause servers to store data in a different field order than
217-
applications. If metaFields are objects, queries on entire metaFields
218-
may produce inconsistent results because metaField order may vary
219-
between servers and applications. To optimize queries on time-series
220-
metaFields, query timeseries metaFields on scalar sub-fields rather than
221-
entire metaFields.
222-
223-
The following example creates a time series collection:
224-
225-
.. code-block:: javascript
226-
227-
db.weather.insertMany( [
228-
{
229-
"metaField": { "sensorId": 5578, "type": "temperature" },
230-
"timestamp": ISODate( "2021-05-18T00:00:00.000Z" ),
231-
"temp": 12
232-
},
233-
{
234-
"metaField": { "sensorId": 5578, "type": "temperature" },
235-
"timestamp": ISODate( "2021-05-18T04:00:00.000Z" ),
236-
"temp": 11
237-
}
238-
] )
239-
240-
The following query on the ``sensorId`` and ``type`` scalar sub-fields
241-
returns the first document that matches the query criteria:
242-
243-
.. code-block:: javascript
244-
245-
db.weather.findOne( {
246-
"metaField.sensorId": 5578,
247-
"metaField.type": "temperature"
248-
} )
249-
250-
Example output:
251-
252-
.. code-block:: javascript
253-
:copyable: false
254-
255-
{
256-
_id: ObjectId("6572371964eb5ad43054d572"),
257-
metaField: { sensorId: 5578, type: 'temperature' },
258-
timestamp: ISODate( "2021-05-18T00:00:00.000Z" ),
259-
temp: 12
260-
}
212+
To improve query performance,
213+
:ref:`create one or more secondary indexes <timeseries-add-secondary-index>`
214+
on your ``timeField`` and ``metaField`` to support common query
215+
patterns.

source/core/timeseries/timeseries-migrate-data-into-timeseries-collection.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,23 @@ The command returns the following output:
239239
:binary:`~bin.mongorestore` cannot create indexes on time series
240240
collections.
241241

242-
If your original collection had secondary indexes, manually recreate them
243-
now.
242+
If your original collection had secondary indexes, manually recreate
243+
them now. If your collection includes ``timeField`` values before
244+
``1970-01-01T00:00:00.000Z`` or after ``2038-01-19T03:14:07.000Z``,
245+
MongoDB logs a warning and disables some query optimizations that make
246+
use of the :ref:`internal clustered index <manual-timeseries-internal-index>`. :ref:`Create a secondary index
247+
<timeseries-add-secondary-index>` on the ``timeField`` to regain query
248+
performance and resolve the log warning.
244249

245250
.. seealso::
246251

247252
:ref:`timeseries-add-secondary-index`
253+
254+
255+
If you insert a document into a collection with a ``timeField``
256+
value before ``1970-01-01T00:00:00.000Z`` or after
257+
``2038-01-19T03:14:07.000Z``,
258+
MongoDB logs a warning and prevents some query optimizations from
259+
using the internal index. :ref:`Create a secondary index <timeseries-add-secondary-index>`
260+
on the ``timeField`` to regain query performance and resolve the log
261+
warning.

source/core/timeseries/timeseries-secondary-index.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,20 @@ measurements from weather sensors:
116116
]
117117
)
118118

119-
Time Series collections automatically create a clustered index. The
120-
clustered index may automatically be used by the query planner to
121-
improve sort performance in some situations. For more information on
122-
clustered indexes, see :ref:`clustered index
123-
<db.createCollection.clusteredIndex>`.
124-
125-
The following sort operation on the timestamp field uses the clustered
126-
index to improve performance:
119+
Time Series collections automatically create an internal :ref:`clustered index <db.createCollection.clusteredIndex>`.
120+
The query planner uses this index to improve sort performance.
121+
122+
.. note::
123+
If you insert a document into a collection with a ``timeField``
124+
value before ``1970-01-01T00:00:00.000Z`` or after
125+
``2038-01-19T03:14:07.000Z``,
126+
MongoDB logs a warning and prevents some query optimizations from
127+
using the internal index. :ref:`Create a secondary index <timeseries-add-secondary-index>`
128+
on the ``timeField`` to regain query performance and resolve the log
129+
warning.
130+
131+
The following sort operation on the ``timestamp`` field uses the
132+
clustered index to improve performance:
127133

128134
.. code-block:: javascript
129135

0 commit comments

Comments
 (0)