Skip to content

Commit e70a664

Browse files
DOCSP-28095 Backport bucket unpacking with sorting to 5.0 (#6835)
* (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 * fix build error * add missing include
1 parent 2f64d8d commit e70a664

File tree

3 files changed

+97
-9
lines changed

3 files changed

+97
-9
lines changed

snooty.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ package-name-enterprise = "mongodb-enterprise"
222222
package-name = "mongodb"
223223
version = "5.0"
224224
latest-lts-version = "5.0"
225-
minimum-lts-version = "5.0"
226225
release = "5.0.25"
227226
last-supported-version = "4.4"
228227
version-dev = "5.3"

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

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,100 @@ fields:
4242

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

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

48-
To force MongoDB to use a specific index when querying a :term:`time
49-
series collection`, use :method:`cursor.hint()` with an index name:
47+
Use Secondary Indexes to Improve Sort Performance
48+
-------------------------------------------------
49+
50+
Sort operations on the ``timeField`` and ``metaField`` can use secondary
51+
indexes on those fields to improve performance.
52+
53+
For example, the following ``sensorData`` collection contains
54+
temperature readings:
55+
56+
.. code-block:: javascript
57+
58+
db.sensorData.insertMany( [
59+
{
60+
"metadata": { "sensorId": 5578, "type": "temperature" },
61+
"timestamp": ISODate("2022-01-15T00:00:00.000Z"),
62+
"temperatureReading": 12
63+
},
64+
{
65+
"metadata": { "sensorId": 5578, "type": "temperature" },
66+
"timestamp": ISODate("2022-01-15T04:00:00.000Z"),
67+
"temperatureReading": 11
68+
},
69+
{
70+
"metadata": { "sensorId": 5579, "type": "temperature" },
71+
"timestamp": ISODate("2022-01-15T08:00:00.000Z"),
72+
"temperatureReading": 9
73+
}
74+
] )
75+
76+
The following command creates a compound ascending secondary index on
77+
the ``timestamp`` and ``metadata.sensorId`` fields:
78+
79+
.. code-block:: javascript
80+
81+
db.sensorData.createIndex(
82+
{ "timestamp": 1, "metadata.sensorId": 1 }
83+
)
84+
85+
The following sort operation on the ``timestamp`` field uses the index
86+
to improve performance:
87+
88+
.. code-block:: javascript
89+
90+
db.sensorData.find().sort( { "timestamp": 1 } )
91+
92+
To confirm that the sort operation used the index, run the operation
93+
again with the ``.explain()`` option:
94+
95+
.. code-block:: javascript
96+
97+
db.sensorData.find().sort( { "timestamp": 1 } ).explain()
98+
99+
The ``winningPlan.queryPlan.inputStage.stage`` is ``IXSCAN``, which
100+
indicates that the index was used. For more information on explain plan
101+
output, see :ref:`explain-results`.
102+
103+
Specify Index Hints for Time Series Collections
104+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105+
106+
Index hints cause MongoDB to use a specific index for a query. Some
107+
operations on time series collections can only take advantage of an
108+
index if that index is specified in a hint.
109+
110+
For example, the following query causes MongoDB to use the
111+
``timestamp_1_metadata.sensorId_1`` index:
50112

51113
.. code-block:: javascript
52114

53-
db.weather24h.find({ "metadata.sensorId": 1235 }).hint("metadata.sensorId_1_timestamp_1")
115+
db.sensorData.find( { "metadata.sensorId": 5578 } ).hint( "timestamp_1_metadata.sensorId_1" )
116+
117+
On a time series collection, you can specify hints using either the
118+
index name or the index key pattern. To get the names of the indexes on
119+
a collection, use the :method:`db.collection.getIndexes()` method.
120+
121+
.. _timeseries-add-secondary-index-mongodb-6.0:
122+
123+
Time Series Secondary Indexes
124+
-----------------------------
125+
126+
Starting in MongoDB 6.0 (and 5.0.16):
127+
128+
- You can add a :doc:`compound index </core/index-compound>` on time,
129+
metadata, or measurement fields.
130+
131+
- You can use the :query:`$or`, :query:`$in`, and :query:`$geoWithin`
132+
operators with :doc:`partial indexes </core/index-partial>` on a time
133+
series collection.
134+
135+
- You can add :doc:`partial </core/index-partial>` and :doc:`2dsphere
136+
</core/2dsphere>` indexes on any field in a :ref:`time series
137+
collection <manual-timeseries-collection>`.
138+
139+
.. note::
54140

55-
On a time series collection, you can only specify hints using the index
56-
name, not the index key pattern. To get the names of the indexes on a
57-
collection, use the :method:`db.collection.getIndexes()` method.
141+
.. include:: /includes/time-series-secondary-indexes-downgrade-FCV.rst
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
If there are :term:`secondary indexes <secondary index>` on :ref:`time
2+
series collections <manual-timeseries-collection>` and you need to
3+
downgrade the feature compatibility version (FCV), you must first drop
4+
any secondary indexes that are incompatible with the downgraded FCV.
5+
See :dbcommand:`setFeatureCompatibilityVersion`.

0 commit comments

Comments
 (0)