@@ -68,8 +68,8 @@ MongoDB supports a number of different index types to support querying
6868your data. The following sections describe the most common index types
6969and provide sample code for creating each index type.
7070
71- Single Field and Compound Indexes
72- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71+ Single Field Indexes
72+ ~~~~~~~~~~~~~~~~~~~~
7373
7474**Single field indexes** are indexes that improve performance for queries
7575that specify ascending or descending sort order on a single field of a
@@ -83,6 +83,7 @@ the ``sample_mflix`` database.
8383 :language: js
8484 :start-after: begin-idx
8585 :end-before: end-idx
86+ :dedent:
8687
8788The following is an example of a query that would be covered by the index
8889created above.
@@ -91,9 +92,12 @@ created above.
9192 :language: js
9293 :start-after: begin-query
9394 :end-before: end-query
95+ :dedent:
9496
95- See the MongoDB server manual section on
96- :manual:`single field indexes </core/index-single>` for more information.
97+ To learn more, see :manual:`Single Field Indexes </core/index-single>`.
98+
99+ Compound Indexes
100+ ~~~~~~~~~~~~~~~~
97101
98102**Compound indexes** are indexes that improve performance for queries that
99103specify ascending or descending sort order for *multiple* fields of
@@ -108,6 +112,7 @@ index on the ``type`` and ``genre`` fields in the ``movies`` collection in the
108112 :language: js
109113 :start-after: begin-idx
110114 :end-before: end-idx
115+ :dedent:
111116
112117The following is an example of a query that would be covered by the index
113118created above.
@@ -116,9 +121,9 @@ created above.
116121 :language: js
117122 :start-after: begin-query
118123 :end-before: end-query
124+ :dedent:
119125
120- See the MongoDB server manual section on
121- :manual:`Compound indexes </core/index-compound>` for more information.
126+ To learn more, see :manual:`Compound Indexes </core/index-compound>`.
122127
123128Multikey Indexes (Indexes on Array Fields)
124129~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -136,6 +141,7 @@ the ``sample_mflix`` database.
136141 :language: js
137142 :start-after: begin-idx
138143 :end-before: end-idx
144+ :dedent:
139145
140146The following is an example of a query that would be covered by the index
141147created above.
@@ -144,13 +150,44 @@ created above.
144150 :language: js
145151 :start-after: begin-query
146152 :end-before: end-query
153+ :dedent:
147154
148155Multikey indexes behave differently from non-multikey indexes in terms of
149156query coverage, index bound computation, and sort behavior. For a full
150157explanation of multikey indexes, including a discussion of their behavior
151158and limitations, refer to the :manual:`Multikey Indexes page
152159</core/index-multikey>` in the MongoDB manual.
153160
161+ Clustered Indexes
162+ ~~~~~~~~~~~~~~~~~
163+
164+ **Clustered indexes** are indexes that improve the performance of
165+ insert, update, and delete operations on **clustered collections**.
166+ Clustered collections store documents ordered by the clustered index key
167+ value.
168+
169+ To create a clustered index, specify the ``clusteredIndex`` option in
170+ the ``CollectionOption``. The ``clusteredIndex`` option must specify the
171+ ``_id`` field as the key and the unique field as ``true``.
172+
173+ The following example uses the ``createCollection()`` method to create a
174+ clustered index on the ``_id`` field in the ``vendors`` collection of the
175+ ``tea`` database.
176+
177+ .. code-block:: javascript
178+
179+ const db = client.db('tea');
180+ await db.createCollection('ratings', {
181+ clusteredIndex: {
182+ key: { _id: 1 },
183+ unique: true
184+ }
185+ });
186+
187+ To learn more, see
188+ :ref:`Clustered Indexes <db.createCollection.clusteredIndex>` and
189+ :ref:`Clustered Collections <clustered-collections>`.
190+
154191Text Indexes
155192~~~~~~~~~~~~
156193
@@ -170,6 +207,7 @@ language.
170207 :language: js
171208 :start-after: begin-idx
172209 :end-before: end-idx
210+ :dedent:
173211
174212The following is an example of a query that would be covered by the index
175213created above. Note that the ``sort`` is omitted because text indexes do not
@@ -179,9 +217,9 @@ contain sort order.
179217 :language: js
180218 :start-after: begin-query
181219 :end-before: end-query
220+ :dedent:
182221
183- For a full explanation of text search with MongoDB, refer to
184- :manual:`Text Indexes </core/index-text>` in the MongoDB manual.
222+ To learn more, see :manual:`Text Indexes </core/index-text>`.
185223
186224Geospatial Indexes
187225~~~~~~~~~~~~~~~~~~
@@ -231,17 +269,17 @@ collection in the ``sample_mflix`` database to enable geospatial searches.
231269 :language: js
232270 :start-after: begin-idx
233271 :end-before: end-idx
272+ :dedent:
234273
235274MongoDB also supports ``2d`` indexes for calculating distances on a
236275Euclidean plane and for working with the "legacy coordinate pairs" syntax
237- used in MongoDB 2.2 and earlier. See the
238- :manual:`Geospatial Queries page </geospatial-queries>` in the MongoDB
239- server manual for more further information.
276+ used in MongoDB 2.2 and earlier. To learn more, see
277+ :manual:`Geospatial Queries </geospatial-queries>`.
240278
241279Unique Indexes
242280~~~~~~~~~~~~~~
243281
244- Unique indexes ensure that the indexed fields do not store duplicate
282+ ** Unique indexes** ensure that the indexed fields do not store duplicate
245283values. By default, MongoDB creates a unique index on the ``_id`` field
246284during the creation of a collection. To create a unique index, specify the
247285field or combination of fields that you want to prevent duplication on and
@@ -255,6 +293,7 @@ index on the ``theaterId`` field in the ``theaters`` collection of the
255293 :language: js
256294 :start-after: begin-idx
257295 :end-before: end-idx
296+ :dedent:
258297
259298If you attempt to perform a write operation that stores a duplicate value
260299that violates the unique index, MongoDB will throw an error that resembles
@@ -265,5 +304,4 @@ the following:
265304
266305 E11000 duplicate key error index
267306
268- Refer to the :manual:`Unique Indexes page </core/index-unique>` in the
269- MongoDB server manual for more information.
307+ To learn more, see :manual:`Unique Indexes </core/index-unique>`.
0 commit comments