@@ -31,11 +31,11 @@ field.
3131Create a Sparse Index
3232---------------------
3333
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:
3939
4040.. code-block:: javascript
4141
5555Behavior
5656--------
5757
58- ``sparse`` Index and Incomplete Results
59- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+ Sparse Index and Incomplete Results
59+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6060
6161If a sparse index would result in an incomplete result set for queries
6262and sort operations, MongoDB will not use that index unless a
@@ -69,38 +69,27 @@ behavior.
6969
7070.. include:: /includes/fact-sparse-index-hint-count.rst
7171
72- Indexes that are ``sparse`` by Default
73- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+ Indexes that are Sparse by Default
73+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7474
7575:ref:`2dsphere (version 2) <2dsphere-v2>`, :ref:`2d <2d-index>`,
7676:ref:`geoHaystack <index-geohaystack-index>`, and :ref:`text
77- <index-feature-text>` indexes are always ``sparse``.
78-
79- ``sparse`` Compound Indexes
80- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
77+ <index-feature-text>` indexes are always sparse.
8178
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.
79+ .. _sparse-compound-indexes:
8580
86- For sparse compound indexes that contain a geospatial key (i.e.
87- ``2dsphere``, ``2d``, or ``geoHaystack`` index keys) along
88- with ascending/descending index key(s), only the existence of the
89- geospatial field(s) in a document determine whether the index
90- references the document.
81+ Sparse Compound Indexes
82+ ~~~~~~~~~~~~~~~~~~~~~~~
9183
92- For sparse compound indexes that contain :ref:`text
93- <index-feature-text>` index keys along with ascending/descending index
94- keys, only the existence of the ``text`` index field(s) determine
95- whether the index references a document.
84+ .. include:: /includes/indexes/sparse-compound-indexes.rst
9685
9786.. _sparse-unique-index:
9887
9988``sparse`` and ``unique`` Properties
10089~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10190
102- An index that is both `` sparse`` and :ref:`unique <index-type-unique>`
103- 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
10493field but allows multiple documents that omit the key.
10594
10695Examples
0 commit comments