@@ -9,7 +9,7 @@ Work With Indexes
99.. contents:: On this page
1010 :local:
1111 :backlinks: none
12- :depth: 2
12+ :depth: 3
1313 :class: singlecol
1414
1515Overview
@@ -44,9 +44,12 @@ named ``cuisine_index`` on the ``cuisine`` field in the ``Restaurant`` class:
4444 :end-before: end create index
4545
4646The ``index`` macro defines the index you want to create and the ``create_index``
47- macro creates the index in the ``restaurants`` collection. When defining an
48- index, the field you want to index on goes in the first hash object, and the
49- index options go in the second hash object.
47+ macro creates the index in the ``restaurants`` collection.
48+
49+ When defining an index, the first hash object contains the field you want to
50+ index and its direction. ``1`` represents an ascending index, ``-1`` represents a
51+ descending index. The second hash object contains index options. To learn more
52+ about index options, see the :ref:`mongoid_indexes_api_documentation` section.
5053
5154Aliases and Declaring Indexes
5255+++++++++++++++++++++++++++++
@@ -98,10 +101,10 @@ objects:
98101 :start-after: start create 2dsphere index
99102 :end-before: end create 2dsphere index
100103
101- For more information on 2dsphere indexes, see the :manual:`2dsphere <core/indexes/index-types/geospatial/2dsphere/>`
104+ For more information on 2dsphere indexes, see the :manual:`2dsphere </ core/indexes/index-types/geospatial/2dsphere/>`
102105guide in the {+mdb-server+} manual.
103106
104- For more information on the GeoJSON type, see the :manual:`GeoJSON Objects <reference/geojson/>`
107+ For more information on the GeoJSON type, see the :manual:`GeoJSON Objects </ reference/geojson/>`
105108guide in the {+mdb-server+} manual.
106109
107110Create a Sparse Index
@@ -115,7 +118,7 @@ The following code example defines a sparse index on the ``borough`` field:
115118 :start-after: start create sparse index
116119 :end-before: end create sparse index
117120
118- For more information on sparse indexes, see the :manual:`Sparse Indexes <core/index-sparse/>`
121+ For more information on sparse indexes, see the :manual:`Sparse Indexes </ core/index-sparse/>`
119122guide in the {+mdb-server+} manual.
120123
121124Create Multiple Indexes
@@ -130,21 +133,6 @@ indexes at the same time:
130133 :start-after: start create multiple indexes
131134 :end-before: end create multiple indexes
132135
133- .. TODO checkout what databases does
134-
135- List Indexes
136- ~~~~~~~~~~~~
137-
138- You can list all indexes in your collection. The following example prints all
139- indexes in the ``Restaurant`` model:
140-
141- .. literalinclude:: /includes/reference/indexes.rb
142- :language: ruby
143- :start-after: start list index
144- :end-before: end list index
145-
146- .. TODO test if there's a way to drop single index
147-
148136Drop Indexes
149137~~~~~~~~~~~~
150138
@@ -156,21 +144,32 @@ indexes in the ``Restaurant`` model:
156144 :start-after: start drop indexes
157145 :end-before: end drop indexes
158146
159- .. TODO: Is there a way to only drop 1
147+ .. note:: Default Index
148+
149+ MongoDB creates a default index on the ``_id`` field during the
150+ creation of a collection. This index prevents clients from inserting
151+ two documents with the same values for the ``_id`` field. You cannot
152+ drop this index.
160153
161154Atlas Search Indexes
162155~~~~~~~~~~~~~~~~~~~~
163156
164157You can declare and manage Atlas Search indexes using {+odm+}.
165158
166159To declare a search index, use the ``search_index`` macro within your model. The
167- following code example shows how to declare and create an Atlas Search index:
160+ following code example shows how to declare and create an Atlas Search index
161+ named ``my_search_index``.
162+ The index is on the ``name`` and ``cuisine`` fields and is dynamic.
168163
169164.. literalinclude:: /includes/reference/indexes.rb
170165 :language: ruby
171166 :start-after: start create atlas search index
172167 :end-before: end create atlas search index
173168
169+ To learn more about the syntax for creating an Atlas Search index, see
170+ the :atlas:`Create an Atlas Search Index </atlas-search/create-index/#std-label-ref-create-index>`
171+ guide in the MongoDB Atlas documentation.
172+
174173Remove an Atlas Search Index
175174++++++++++++++++++++++++++++
176175
@@ -186,14 +185,28 @@ following code example shows how to remove an Atlas Search index from the
186185List Atlas Search Indexes
187186+++++++++++++++++++++++++
188187
189- You can list all Atlas Search indexes in your collection by using the
190- ``search_indexes`` macro:
188+ You can enumerate through all Atlas Search indexes in your collection
189+ by using the ``search_indexes`` macro. The following example enumerates through
190+ all Atlas Search indexes in the ``restaurants`` collection and prints out their
191+ information:
191192
192193.. literalinclude:: /includes/reference/indexes.rb
194+ :language: ruby
195+ :start-after: start list atlas search index
196+ :end-before: end list atlas search index
197+
198+ .. _mongoid-indexes-api-documentation:
193199
194200API Documentation
195201-----------------
196202
197203To learn more about using indexes in {+odm+}, see the
198204`Mongoid::Indexable::ClassMethods <{+api-root+}/Indexable/ClassMethods.html>`__
199- guide.
205+ documentation.
206+
207+ To learn more about index options, see the `Mongoid::Indexable::Validators::Options
208+ <{+api-root+}/Indexable/Validators/Options.html>`__ documentation.
209+
210+ To learn more about using Atlas Search indexes in {+odm+}, see the
211+ `Mongoid::SearchIndexable::ClassMethods <{+api-root+}/SearchIndexable/ClassMethods.html>`__
212+ documentation.
0 commit comments