@@ -31,11 +31,11 @@ field.
31
31
Create a Sparse Index
32
32
---------------------
33
33
34
- To create a `` sparse`` index, use the
35
- : method:`db.collection.createIndex()` method with the ``sparse`` option
36
- set to ``true``. For example, the following operation in
37
- :binary:`~bin.mongosh` creates a sparse index on the ``xmpp_id`` field
38
- of the ``addresses`` collection:
34
+ To create a sparse index, use the :method:`db.collection.createIndex()`
35
+ method with the ``sparse`` option set to ``true``.
36
+
37
+ For example, the following operation in :binary:`~bin.mongosh` creates a
38
+ sparse index on the ``xmpp_id`` field of the ``addresses`` collection:
39
39
40
40
.. code-block:: javascript
41
41
55
55
Behavior
56
56
--------
57
57
58
- ``sparse`` Index and Incomplete Results
59
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
+ Sparse Index and Incomplete Results
59
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
60
61
61
If a sparse index would result in an incomplete result set for queries
62
62
and sort operations, MongoDB will not use that index unless a
@@ -69,39 +69,27 @@ behavior.
69
69
70
70
.. include:: /includes/fact-sparse-index-hint-count.rst
71
71
72
- Indexes that are ``sparse`` by Default
73
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
+ Indexes that are Sparse by Default
73
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74
74
75
- :ref:`2dsphere (version 2) <2dsphere-v2>`, :doc :`2d </core/2d >`,
76
- :doc :`geoHaystack </core/ geohaystack>`, and :doc :`text
77
- </core/ index-text>` indexes are always `` sparse`` .
75
+ :ref:`2dsphere (version 2) <2dsphere-v2>`, :ref :`2d <2d-index >`,
76
+ :ref :`geoHaystack <index- geohaystack-index >`, and :ref :`text
77
+ <index-feature- text>` indexes are always sparse.
78
78
79
- ``sparse`` Compound Indexes
80
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
79
+ .. _sparse-compound-indexes:
81
80
82
- Sparse :doc:`compound indexes </core/index-compound>` that only contain
83
- ascending/descending index keys will index a document as long as the
84
- document contains at least one of the keys.
85
-
86
- For sparse compound indexes that contain a geospatial key (i.e.
87
- :doc:`2dsphere </core/2dsphere>`, :doc:`2d </core/2d>`, or
88
- :doc:`geoHaystack </core/geohaystack>` index keys) along with
89
- ascending/descending index key(s), only the existence of the geospatial
90
- field(s) in a document determine whether the index references the
91
- document.
81
+ Sparse Compound Indexes
82
+ ~~~~~~~~~~~~~~~~~~~~~~~
92
83
93
- For sparse compound indexes that contain :doc:`text </core/index-text>`
94
- index keys along with ascending/descending index keys, only the
95
- existence of the ``text`` index field(s) determine whether the index
96
- references a document.
84
+ .. include:: /includes/indexes/sparse-compound-indexes.rst
97
85
98
86
.. _sparse-unique-index:
99
87
100
88
``sparse`` and ``unique`` Properties
101
89
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102
90
103
- An index that is both `` sparse`` and :ref:`unique <index-type-unique>`
104
- prevents collection from having documents with duplicate values for a
91
+ An index that is both sparse and :ref:`unique <index-type-unique>`
92
+ prevents a collection from having documents with duplicate values for a
105
93
field but allows multiple documents that omit the key.
106
94
107
95
Examples
0 commit comments