1
1
.. _kotlin-sync-indexes:
2
2
3
- =============================
4
- Optimize Queries with Indexes
5
- =============================
3
+ =================================
4
+ Optimize Queries by Using Indexes
5
+ =================================
6
6
7
7
.. contents:: On this page
8
8
:local:
@@ -15,7 +15,7 @@ Optimize Queries with Indexes
15
15
:values: reference
16
16
17
17
.. meta::
18
- :description: Learn how to use indexes with the MongoDB {+driver-short+} driver.
18
+ :description: Learn how to use indexes by using the MongoDB Kotlin Sync driver.
19
19
:keywords: query, optimization, efficiency, usage example, code example
20
20
21
21
.. TODO
@@ -28,8 +28,8 @@ Optimize Queries with Indexes
28
28
Overview
29
29
--------
30
30
31
- On this page, you can see copyable code examples that show how to work with common
32
- types of indexes that you can use with the {+driver-short+}.
31
+ On this page, you can see copyable code examples that show how to manage different
32
+ types of indexes by using the {+driver-short+}.
33
33
34
34
.. TODO
35
35
.. .. tip::
@@ -86,8 +86,7 @@ The following example creates a compound index on the specified fields:
86
86
Multikey Index
87
87
--------------
88
88
89
- The following example creates a multikey index on the specified field that contains
90
- array values:
89
+ The following example creates a multikey index on the specified array-valued field:
91
90
92
91
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
93
92
:start-after: start-multikey
@@ -99,150 +98,154 @@ array values:
99
98
.. TODO To learn more about multikey indexes, see the :ref:`kotlin-sync-multikey-index`
100
99
.. guide.
101
100
102
- Atlas Search Index
103
- ------------------
104
-
105
- .. TODO: To learn more about Atlas search indexes, see the :ref:`kotlin-sync-atlas-search-index`
106
- .. guide.
107
-
108
- Create Search Index
109
- ~~~~~~~~~~~~~~~~~~~
101
+ Geospatial Index
102
+ ----------------
110
103
111
- The following example creates an Atlas search index on the specified field:
104
+ The following example creates a 2dsphere index on the specified field that contains
105
+ GeoJSON objects:
112
106
113
107
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
114
- :start-after: start-search-create
115
- :end-before: end-search-create
108
+ :start-after: start-geo
109
+ :end-before: end-geo
116
110
:language: kotlin
117
111
:copyable:
118
112
:dedent:
119
113
120
- .. TODO: To learn more about creating serach indexes, see the :ref:`kotlin-sync-atlas-search- index-create `
114
+ .. TODO: To learn more about geospatial indexes, see the :ref:`kotlin-sync-geospatial- index`
121
115
.. guide.
122
116
123
- List Search Indexes
124
- ~~~~~~~~~~~~~~~~~~~
117
+ Unique Index
118
+ ------------
125
119
126
- The following example prints a list of Atlas search indexes in the specified collection :
120
+ The following example creates a unique index on the specified field :
127
121
128
122
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
129
- :start-after: start-search-list
130
- :end-before: end-search-list
123
+ :start-after: start-unique
124
+ :end-before: end-unique
131
125
:language: kotlin
132
126
:copyable:
133
127
:dedent:
134
128
135
- .. TODO: To learn more about listing search indexes, see the :ref:`kotlin-sync-atlas-search- index-list `
129
+ .. TODO: To learn more about unique indexes, see the :ref:`kotlin-sync-unique- index`
136
130
.. guide.
137
131
138
- Update Search Indexes
139
- ~~~~~~~~~~~~~~~~~~~~~
132
+ Wildcard Index
133
+ --------------
140
134
141
- The following example updates an existing Atlas search index :
135
+ The following example creates a wildcard index in the specified collection :
142
136
143
137
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
144
- :start-after: start-search-update
145
- :end-before: end-search-update
138
+ :start-after: start-wildcard
139
+ :end-before: end-wildcard
146
140
:language: kotlin
147
141
:copyable:
148
142
:dedent:
149
143
150
- .. TODO: To learn more about updating search indexes, see the :ref:`kotlin-sync-atlas-search- index-update `
144
+ .. TODO: To learn more about wildcard indexes, see the :ref:`kotlin-sync-wildcard- index`
151
145
.. guide.
152
146
153
- Delete Search Indexes
154
- ~~~~~~~~~~~~~~~~~~~~~
147
+ Clustered Index
148
+ ---------------
155
149
156
- The following example deletes an Atlas search index with the specified name:
150
+ The following example creates a new collection with a clustered index on the ``_id``
151
+ field:
157
152
158
153
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
159
- :start-after: start-search-delete
160
- :end-before: end-search-delete
154
+ :start-after: start-clustered
155
+ :end-before: end-clustered
161
156
:language: kotlin
162
157
:copyable:
163
158
:dedent:
164
159
165
- .. TODO: To learn more about deleting search indexes, see the :ref:`kotlin-sync-atlas-search- index-drop `
160
+ .. TODO: To learn more about wildcard indexes, see the :ref:`kotlin-sync-clustered- index`
166
161
.. guide.
167
162
168
- Text Index
169
- ----------
163
+ Atlas Search Index Management
164
+ -----------------------------
165
+
166
+ The following sections contain code examples that describe how to manage Atlas Search
167
+ indexes.
168
+
169
+ .. TODO: To learn more about Atlas search indexes, see the :ref:`kotlin-sync-atlas-search-index`
170
+ .. guide.
171
+
172
+ Create Search Index
173
+ ~~~~~~~~~~~~~~~~~~~
170
174
171
- The following example creates a text index on the specified field:
175
+ The following example creates an Atlas search index on the specified field:
172
176
173
177
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
174
- :start-after: start-text
175
- :end-before: end-text
178
+ :start-after: start-search-create
179
+ :end-before: end-search-create
176
180
:language: kotlin
177
181
:copyable:
178
182
:dedent:
179
183
180
- .. TODO: To learn more about text indexes, see the :ref:`kotlin-sync-text- index`
184
+ .. TODO: To learn more about creating serach indexes, see the :ref:`kotlin-sync-atlas-search- index-create `
181
185
.. guide.
182
186
183
- Geospatial Index
184
- ----------------
187
+ List Search Indexes
188
+ ~~~~~~~~~~~~~~~~~~~
185
189
186
- The following example creates a 2dsphere index on the specified field that contains
187
- GeoJSON objects:
190
+ The following example prints a list of Atlas search indexes in the specified collection:
188
191
189
192
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
190
- :start-after: start-geo
191
- :end-before: end-geo
193
+ :start-after: start-search-list
194
+ :end-before: end-search-list
192
195
:language: kotlin
193
196
:copyable:
194
197
:dedent:
195
198
196
- .. TODO: To learn more about geospatial indexes, see the :ref:`kotlin-sync-geospatial- index`
199
+ .. TODO: To learn more about listing search indexes, see the :ref:`kotlin-sync-atlas-search- index-list `
197
200
.. guide.
198
201
199
- Unique Index
200
- ------------
202
+ Update Search Indexes
203
+ ~~~~~~~~~~~~~~~~~~~~~
201
204
202
- The following example creates a unique index on the specified field:
205
+ The following example updates an existing Atlas search index with the specified
206
+ new index definition:
203
207
204
208
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
205
- :start-after: start-unique
206
- :end-before: end-unique
209
+ :start-after: start-search-update
210
+ :end-before: end-search-update
207
211
:language: kotlin
208
212
:copyable:
209
213
:dedent:
210
214
211
- .. TODO: To learn more about unique indexes, see the :ref:`kotlin-sync-unique- index`
215
+ .. TODO: To learn more about updating search indexes, see the :ref:`kotlin-sync-atlas-search- index-update `
212
216
.. guide.
213
217
214
- Wildcard Index
215
- --------------
218
+ Delete Search Indexes
219
+ ~~~~~~~~~~~~~~~~~~~~~
216
220
217
- The following example creates a wildcard index in the specified collection :
221
+ The following example deletes an Atlas search index with the specified name :
218
222
219
223
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
220
- :start-after: start-wildcard
221
- :end-before: end-wildcard
224
+ :start-after: start-search-delete
225
+ :end-before: end-search-delete
222
226
:language: kotlin
223
227
:copyable:
224
228
:dedent:
225
229
226
- .. TODO: To learn more about wildcard indexes, see the :ref:`kotlin-sync-wildcard- index`
230
+ .. TODO: To learn more about deleting search indexes, see the :ref:`kotlin-sync-atlas-search- index-drop `
227
231
.. guide.
228
232
229
- Clustered Index
230
- ---------------
233
+ Text Index
234
+ ----------
231
235
232
- The following example creates a new collection with a clustered index on the ``_id``
233
- field:
236
+ The following example creates a text index on the specified string field:
234
237
235
238
.. literalinclude:: /includes/usage-examples/index-code-examples.kt
236
- :start-after: start-clustered
237
- :end-before: end-clustered
239
+ :start-after: start-text
240
+ :end-before: end-text
238
241
:language: kotlin
239
242
:copyable:
240
243
:dedent:
241
244
242
- .. TODO: To learn more about wildcard indexes, see the :ref:`kotlin-sync-clustered -index`
245
+ .. TODO: To learn more about text indexes, see the :ref:`kotlin-sync-text -index`
243
246
.. guide.
244
247
245
- Remove an Index
248
+ Delete an Index
246
249
---------------
247
250
248
251
The following example deletes an index with the specified name:
0 commit comments