File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 3
3
from django .db .models import Q , F
4
4
from django_mongodb_backend .models import EmbeddedModel
5
5
from django_mongodb_backend .fields import EmbeddedModelField , ArrayField
6
+ from django_mongodb_backend .indexes import SearchIndex
6
7
7
8
class Nutrition (EmbeddedModel ):
8
9
calories = models .IntegerField (default = 0 )
@@ -60,6 +61,15 @@ class Meta:
60
61
]
61
62
# end-embedded
62
63
64
+ # start-atlas-search
65
+ class Meta :
66
+ db_table = "recipes"
67
+ indexes = [
68
+ SearchIndex (fields = ["title" ],
69
+ name = "title_search_idx" ),
70
+ ]
71
+ # end-atlas-search
72
+
63
73
# start-partial
64
74
class Meta :
65
75
db_table = "recipes"
Original file line number Diff line number Diff line change @@ -202,9 +202,41 @@ Advanced Index Configuration
202
202
This section shows how to create the following advanced
203
203
index types:
204
204
205
+ - :ref:`django-indexes-atlas-search`
205
206
- :ref:`django-indexes-partial`
206
207
- :ref:`django-indexes-unique`
207
208
209
+ .. _django-indexes-atlas-search:
210
+
211
+ Atlas Search Indexes
212
+ ~~~~~~~~~~~~~~~~~~~~
213
+
214
+ Atlas Search indexes specify the behavior of an Atlas Search, or a full-text
215
+ search on collections hosted on MongoDB Atlas.
216
+
217
+ To create an Atlas Search index, assign the ``indexes`` option in your model's
218
+ ``Meta`` class to a ``SearchIndex`` object. Pass the following arguments to the
219
+ ``SearchIndex()`` constructor:
220
+
221
+ - ``fields``: The fields you want to index.
222
+ - ``name``: *(Optional)* The name of your Atlas Search index. If you do not
223
+ specify this argument, {+django-odm+} automatically generates an index name.
224
+
225
+ The following example updates the ``Recipe`` model's ``Meta`` class to create
226
+ an Atlas Search index named ``"title_search_idx"`` on the ``title`` field:
227
+
228
+ .. literalinclude:: /includes/model-data/indexes.py
229
+ :start-after: start-atlas-search
230
+ :end-before: end-atlas-search
231
+ :language: python
232
+ :copyable:
233
+ :emphasize-lines: 3-6
234
+
235
+ .. tip::
236
+
237
+ To learn more about Atlas Search queries and indexes, see :atlas:`Atlas Search </atlas-search>`
238
+ in the Atlas documentation.
239
+
208
240
.. _django-indexes-partial:
209
241
210
242
Partial Indexes
You can’t perform that action at this time.
0 commit comments