Skip to content

Commit 703e2f5

Browse files
(DOCSP-22479): Bucket unpacking with sorting (#1100)
* (DOCSP-22479): Bucket unpacking with sorting * tweak example * wording * typo * revert collection name change * edits * fix example * typo * update release notes * wording * updates per review * reorg release notes
1 parent e79d700 commit 703e2f5

File tree

2 files changed

+89
-41
lines changed

2 files changed

+89
-41
lines changed

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

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,77 @@ fields:
4343

4444
:method:`db.collection.createIndex()`
4545

46-
Index Hints for Time Series Collections
47-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
.. _timeseries-secondary-index-sort-performance:
4847

49-
To force MongoDB to use a specific index when querying a :term:`time
50-
series collection`, use :method:`cursor.hint()` with an index name:
48+
Use Secondary Indexes to Improve Sort Performance
49+
-------------------------------------------------
50+
51+
Sort operations on the ``timeField`` and ``metaField`` can use secondary
52+
indexes on those fields to improve performance.
53+
54+
For example, the following ``sensorData`` collection contains
55+
temperature readings:
56+
57+
.. code-block:: javascript
58+
59+
db.sensorData.insertMany( [
60+
{
61+
"metadata": { "sensorId": 5578, "type": "temperature" },
62+
"timestamp": ISODate("2022-01-15T00:00:00.000Z"),
63+
"temperatureReading": 12
64+
},
65+
{
66+
"metadata": { "sensorId": 5578, "type": "temperature" },
67+
"timestamp": ISODate("2022-01-15T04:00:00.000Z"),
68+
"temperatureReading": 11
69+
},
70+
{
71+
"metadata": { "sensorId": 5579, "type": "temperature" },
72+
"timestamp": ISODate("2022-01-15T08:00:00.000Z"),
73+
"temperatureReading": 9
74+
}
75+
] )
76+
77+
The following command creates a compound ascending secondary index on
78+
the ``timestamp`` and ``metadata.sensorId`` fields:
79+
80+
.. code-block:: javascript
81+
82+
db.sensorData.createIndex(
83+
{ "timestamp": 1, "metadata.sensorId": 1 }
84+
)
85+
86+
The following sort operation on the ``timestamp`` field uses the index
87+
to improve performance:
88+
89+
.. code-block:: javascript
90+
91+
db.sensorData.find().sort( { "timestamp": 1 } )
92+
93+
To confirm that the sort operation used the index, run the operation
94+
again with the ``.explain()`` option:
5195

5296
.. code-block:: javascript
5397

54-
db.weather24h.find({ "metadata.sensorId": 1235 }).hint("metadata.sensorId_1_timestamp_1")
98+
db.sensorData.find().sort( { "timestamp": 1 } ).explain()
99+
100+
The ``winningPlan.queryPlan.inputStage.stage`` is ``IXSCAN``, which
101+
indicates that the index was used. For more information on explain plan
102+
output, see :ref:`explain-results`.
103+
104+
Specify Index Hints for Time Series Collections
105+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106+
107+
Index hints cause MongoDB to use a specific index for a query. Some
108+
operations on time series collections can only take advantage of an
109+
index if that index is specified in a hint.
110+
111+
For example, the following query causes MongoDB to use the
112+
``timestamp_1_metadata.sensorId_1`` index:
113+
114+
.. code-block:: javascript
115+
116+
db.sensorData.find( { "metadata.sensorId": 5578 } ).hint( "timestamp_1_metadata.sensorId_1" )
55117

56118
On a time series collection, you can specify hints using either the
57119
index name or the index key pattern. To get the names of the indexes on
@@ -60,7 +122,7 @@ a collection, use the :method:`db.collection.getIndexes()` method.
60122
.. _timeseries-add-secondary-index-mongodb-6.0:
61123

62124
Time Series Secondary Indexes in MongoDB 6.0
63-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125+
--------------------------------------------
64126

65127
Starting in MongoDB 6.0:
66128

@@ -78,29 +140,3 @@ Starting in MongoDB 6.0:
78140
.. note::
79141

80142
.. include:: /includes/time-series-secondary-indexes-downgrade-FCV.rst
81-
82-
For example, the following ``sensorData`` collection contains
83-
temperature readings:
84-
85-
.. code-block:: javascript
86-
87-
db.sensorData.insertMany( [
88-
{
89-
"metadata": { "sensorId": 5578, "type": "temperature" },
90-
"timestamp": ISODate("2022-01-15T00:00:00.000Z"),
91-
"temperatureReading": 12
92-
},
93-
{
94-
"metadata": { "sensorId": 5578, "type": "temperature" },
95-
"timestamp": ISODate("2022-01-15T04:00:00.000Z"),
96-
"temperatureReading": 11
97-
}
98-
] )
99-
100-
The following example creates an ascending secondary index on the
101-
``metadata.sensorId`` and ``temperatureReading`` fields in the
102-
``sensorData`` collection:
103-
104-
.. code-block:: javascript
105-
106-
db.sensorData.createIndex( { "metadata.sensorId": 1, "temperatureReading": 1 } )

source/release-notes/6.0.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ Starting in MongoDB 6.0 (and 5.0.9, 4.4.14, 4.2.20), MongoDB
4646
installations on macOS are notarized. When installing on macOS, you no
4747
longer need to instruct macOS to trust MongoDB binaries.
4848

49+
Time Series Collections
50+
-----------------------
51+
52+
MongoDB 6.0 introduces the following improvements and new features for
53+
time series collections:
54+
55+
Additional Secondary Index Types
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
58+
You can add additional :term:`secondary index <secondary index>` types
59+
to :ref:`time series collections <manual-timeseries-collection>`. See
60+
:ref:`timeseries-add-secondary-index-mongodb-6.0` for the additional
61+
indexes and other improvements.
62+
63+
Sort Operations Use Secondary Indexes
64+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65+
66+
Sort operations on time series collections can use indexes to improve
67+
performance. For more information and an example, see
68+
:ref:`timeseries-secondary-index-sort-performance`.
69+
4970
Stable API
5071
----------
5172

@@ -74,15 +95,6 @@ see :ref:`stable-api-changelog`.
7495
General Improvements
7596
--------------------
7697

77-
Time Series Collection Improvements
78-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79-
80-
Starting in MongoDB 6.0, you can add additional :term:`secondary index
81-
<secondary index>` types to :ref:`time series collections
82-
<manual-timeseries-collection>`. See
83-
:ref:`timeseries-add-secondary-index-mongodb-6.0` for the additional
84-
indexes and other improvements.
85-
8698
Capped Collections Improvements
8799
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88100

0 commit comments

Comments
 (0)