-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathindexes.txt
More file actions
217 lines (160 loc) · 5.22 KB
/
indexes.txt
File metadata and controls
217 lines (160 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
.. _pymongo-indexes:
=============================
Optimize Queries with Indexes
=============================
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
.. facet::
:name: genre
:values: reference
.. meta::
:description: Learn how to use indexes with the MongoDB {+driver-short+} driver.
:keywords: query, optimization, efficiency, usage example, code example
.. toctree::
:titlesonly:
:maxdepth: 1
Work with Indexes </work-with-indexes>
Overview
--------
On this page, you can see copyable code examples that show how to work with common
types of indexes that you can use with {+driver-short+}.
.. tip::
To learn more about working with indexes, see the :ref:`pymongo-work-with-indexes`
guide. To learn more about any of the indexes shown on this page, see the link
provided in each section.
To use an example from this page, copy the code example into the
:ref:`sample application <pymongo-index-sample>` or your own application.
Be sure to replace all placeholders in the code examples, such as ``<connection string URI>``, with
the relevant values for your MongoDB deployment.
.. _pymongo-index-sample:
.. include:: /includes/usage-examples/sample-app-intro.rst
.. literalinclude:: /includes/usage-examples/sample-app.py
:language: python
:copyable:
:linenos:
:emphasize-lines: 11-13
Single Field Index
------------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-single-field
:end-before: end-single-field
:language: python
:copyable:
To learn more about single field indexes, see the
:ref:`pymongo-single-field-index` guide.
Compound Index
--------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-compound
:end-before: end-compound
:language: python
:copyable:
To learn more about compound indexes, see the :ref:`pymongo-compound-index`
guide.
Multikey Index
--------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-multikey
:end-before: end-multikey
:language: python
:copyable:
To learn more about multikey indexes, see the :ref:`pymongo-multikey-index`
guide.
Atlas Search Index
------------------
To learn more about Atlas search indexes, see the :ref:`pymongo-atlas-search-index`
guide.
Create Search Index
~~~~~~~~~~~~~~~~~~~
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-search-create
:end-before: end-search-create
:language: python
:copyable:
To learn more about creating search indexes, see the :ref:`pymongo-atlas-search-index-create`
guide.
List Search Indexes
~~~~~~~~~~~~~~~~~~~
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-search-list
:end-before: end-search-list
:language: python
:copyable:
To learn more about listing search indexes, see the :ref:`pymongo-atlas-search-index-list`
guide.
Update Search Indexes
~~~~~~~~~~~~~~~~~~~~~
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-search-update
:end-before: end-search-update
:language: python
:copyable:
To learn more about updating search indexes, see the :ref:`pymongo-atlas-search-index-update`
guide.
Delete Search Indexes
~~~~~~~~~~~~~~~~~~~~~
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-search-drop
:end-before: end-search-drop
:language: python
:copyable:
To learn more about deleting search indexes, see the :ref:`pymongo-atlas-search-index-drop`
guide.
Text Index
----------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-text
:end-before: end-text
:language: python
:copyable:
To learn more about text indexes, see the :ref:`pymongo-text-index`
guide.
.. _geospatial-indexes:
Geospatial Index
----------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-geo
:end-before: end-geo
:language: python
:copyable:
To learn more about geospatial indexes, see the :ref:`pymongo-geospatial-index`
guide.
Unique Index
------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-unique
:end-before: end-unique
:language: python
:copyable:
To learn more about unique indexes, see the :ref:`pymongo-unique-index`
guide.
Wildcard Index
--------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-wildcard
:end-before: end-wildcard
:language: python
:copyable:
To learn more about wildcard indexes, see the :ref:`pymongo-wildcard-index`
guide.
Clustered Index
---------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-clustered
:end-before: end-clustered
:language: python
:copyable:
To learn more about wildcard indexes, see the :ref:`pymongo-clustered-index`
guide.
Remove an Index
---------------
.. literalinclude:: /includes/usage-examples/index-code-examples.py
:start-after: start-remove
:end-before: end-remove
:language: python
:copyable:
To learn more about removing indexes, see :ref:`pymongo-indexes-remove`
in the Work with Indexes guide.