Skip to content

Commit 49130ea

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCS-16516-value-comparisons-match-expression (#5485)
* DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression * DOCS-16516-value-comparisons-match-expression --------- Co-authored-by: jason-price-mongodb <[email protected]>
1 parent b2b9bfe commit 49130ea

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

source/core/index-partial.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ the ``sparse`` option.
183183

184184
Shard key indexes cannot be partial indexes.
185185

186+
.. _index-partial-equivalent-indexes:
187+
188+
Equivalent Indexes
189+
~~~~~~~~~~~~~~~~~~
190+
191+
.. include:: /includes/indexes/equivalent-indexes.rst
192+
193+
For an example, see :ref:`index-partial-equivalent-indexes-example`.
194+
186195
Examples
187196
--------
188197

@@ -296,3 +305,70 @@ greater than or equal to 21.
296305
{ username: "amanda" },
297306
{ username: "rajiv", age: null }
298307
] )
308+
309+
.. _index-partial-equivalent-indexes-example:
310+
311+
Equivalent Indexes Example
312+
~~~~~~~~~~~~~~~~~~~~~~~~~~
313+
314+
.. include:: /includes/indexes/equivalent-indexes.rst
315+
316+
In previous MongoDB versions, you can create two equivalent indexes. The
317+
following example creates a ``pizzas`` collection and two equivalent
318+
indexes named ``index0`` and ``index1``:
319+
320+
.. code-block:: javascript
321+
322+
// Create the pizzas collection
323+
db.pizzas.insertMany( [
324+
{ _id: 0, type: "pepperoni", size: "small", price: 4 },
325+
{ _id: 1, type: "cheese", size: "medium", price: 7 },
326+
{ _id: 2, type: "vegan", size: "large", price: 8 }
327+
] )
328+
329+
// Create two equivalent indexes with medium pizza sizes
330+
db.pizzas.createIndex(
331+
{ type: 1 },
332+
{ name: "index0",
333+
partialFilterExpression: { size: "medium" },
334+
collation: { locale: "en_US", strength: 1 }
335+
}
336+
)
337+
338+
db.pizzas.createIndex(
339+
{ type: 1 },
340+
{ name: "index1",
341+
partialFilterExpression: { size: "MEDIUM" },
342+
collation: { locale: "en_US", strength: 1 }
343+
}
344+
)
345+
346+
The indexes are equivalent because the two indexes specify the same
347+
pizza size and only differ in the text case in the partial filter
348+
expression. Only one index is used by queries: the index that was
349+
created first, which is ``index0`` in the previous example.
350+
351+
Starting in MongoDB 7.3, you cannot create the second index (``index1``)
352+
and this error is returned:
353+
354+
.. code-block:: none
355+
:copyable: false
356+
357+
MongoServerError: Index already exists with a different name: index0
358+
359+
In MongoDB versions earlier than 7.3, you can create the indexes but
360+
only the first index (``index0``) is used with these queries:
361+
362+
.. code-block:: javascript
363+
364+
db.pizzas.find( { type: "cheese", size: "medium" } ).collation(
365+
{ locale: "en_US", strength: 1 }
366+
)
367+
368+
db.pizzas.find( { type: "cheese", size: "MEDIUM" } ).collation(
369+
{ locale: "en_US", strength: 1 }
370+
)
371+
372+
db.pizzas.find( { type: "cheese", size: "Medium" } ).collation(
373+
{ locale: "en_US", strength: 1 }
374+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Starting in MongoDB 7.3, you cannot create equivalent indexes, which are
2+
partial indexes with the same index keys and the same partial
3+
expressions that use a :ref:`collation <collation>`.
4+
5+
For databases in MongoDB 7.3 with existing equivalent indexes, the
6+
indexes are retained but only the first equivalent index is used in
7+
queries. This is the same behavior as MongoDB versions earlier than 7.3.

source/reference/command/analyzeShardKey.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,3 @@ Learn More
214214
- :ref:`sharding-reference`
215215
- :method:`sh.shardCollection()`
216216
- :dbcommand:`refineCollectionShardKey`
217-
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. _7.3-compatibility:
2+
3+
====================================
4+
Compatibility Changes in MongoDB 7.3
5+
====================================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. _7.3-downgrade-incompatible:
16+
17+
.. include:: /includes/rc-available.rst
18+
19+
.. include:: /includes/rapid-release-short.rst
20+
21+
Backward-Incompatible Features
22+
------------------------------
23+
24+
General Changes
25+
---------------
26+
27+
Equivalent Indexes
28+
~~~~~~~~~~~~~~~~~~
29+
30+
.. include:: /includes/indexes/equivalent-indexes.rst
31+
32+
For an example, see :ref:`index-partial-equivalent-indexes-example`.

0 commit comments

Comments
 (0)