@@ -22,13 +22,13 @@ Overview
22
22
23
23
In this guide, you can learn how to create MongoDB **indexes** by using your
24
24
Django models. Indexes can improve the efficiency of queries and add
25
- additional functionality to querying and storing documents .
25
+ additional query and document storage functionality .
26
26
27
27
Without indexes, MongoDB must scan every document in a collection to find the
28
28
documents that match each query. These collection scans are
29
29
slow and can negatively affect the performance of your application. However, if an
30
30
appropriate index exists for a query, MongoDB can use the index to limit the
31
- documents it must inspect .
31
+ documents it inspects .
32
32
33
33
Django provides the ``Index`` class, which you can use to create an
34
34
index on your model. {+django-odm+} creates the same index on your
@@ -47,7 +47,7 @@ The examples in this guide use the ``Recipe`` model, which contains an
47
47
embedded ``Nutrition`` model as the value of its ``nutrition`` field.
48
48
These model classes have the following definitions:
49
49
50
- .. literalinclude:: /includes/interact -data/specify-a-query .py
50
+ .. literalinclude:: /includes/model -data/indexes .py
51
51
:start-after: start-models
52
52
:end-before: end-models
53
53
:language: python
@@ -76,11 +76,11 @@ code:
76
76
# add more indexes here
77
77
]
78
78
79
- To define your index, pass the following arguments to the ``Index()`` method:
79
+ To define your index, pass the following arguments to the ``models. Index()`` method:
80
80
81
81
- ``expressions``: Specifies a database expression to index. If you don't pass
82
82
the ``fields`` argument, this argument is required. To learn more about this
83
- argument, see the :ref:`django-indexes-expressions ` section of this guide.
83
+ argument, see the :ref:`django-indexes-functions ` section of this guide.
84
84
85
85
- ``fields``: Specifies a list of fields to index. If you don't pass the
86
86
``expressions`` argument, this argument is required.
@@ -189,8 +189,8 @@ an index on the ``nutrition`` embedded model field, which {+django-odm+} creates
189
189
on the ``recipes`` collection:
190
190
191
191
.. literalinclude:: /includes/model-data/indexes.py
192
- :start-after: start-multikey
193
- :end-before: end-multikey
192
+ :start-after: start-embedded
193
+ :end-before: end-embedded
194
194
:language: python
195
195
:copyable:
196
196
:emphasize-lines: 3-5
@@ -211,7 +211,7 @@ Partial Indexes
211
211
~~~~~~~~~~~~~~~
212
212
213
213
Partial indexes index only the documents in a collection that meet specified
214
- filter condition , which reduces storage use and performance costs.
214
+ filter criteria , which reduces storage use and performance costs.
215
215
216
216
To create a partial index, pass the ``condition`` argument to the ``models.Index()``
217
217
method. Set the condition value to a ``Q`` object that includes the filter
@@ -233,7 +233,7 @@ only index documents that have a ``cook_time`` value less than ``30``:
233
233
:end-before: end-partial
234
234
:language: python
235
235
:copyable:
236
- :emphasize-lines: 3-5
236
+ :emphasize-lines: 3-7
237
237
238
238
.. _django-indexes-unique:
239
239
@@ -275,6 +275,7 @@ creates a unique compound index on these fields:
275
275
:end-before: end-unique-compound
276
276
:language: python
277
277
:copyable:
278
+ :emphasize-lines: 6-8
278
279
279
280
.. tip::
280
281
@@ -295,11 +296,11 @@ The following example updates the ``Recipe`` model's ``Meta`` class to create
295
296
an index on the sum of the ``cook_time`` and ``prep_time`` values:
296
297
297
298
.. literalinclude:: /includes/model-data/indexes.py
298
- :start-after: start-partial
299
- :end-before: end-partial
299
+ :start-after: start-expression
300
+ :end-before: end-expression
300
301
:language: python
301
302
:copyable:
302
- :emphasize-lines: 3-5
303
+ :emphasize-lines: 3-7
303
304
304
305
.. tip::
305
306
@@ -315,7 +316,7 @@ To learn more about the index types mentioned in this guide,
315
316
see the following {+mdb-server+} manual resources:
316
317
317
318
- :manual:`Single Field Indexes </core/index-single/>`
318
- - :manual:`Compound Indexes </core/index-single />`
319
+ - :manual:`Compound Indexes </core/index-compound />`
319
320
- :manual:`Multikey Indexes </core/index-multikey/>`
320
321
- :manual:`Embedded Document Indexes </core/index-single/create-embedded-object-index/>`
321
322
- :manual:`Partial Indexes </core/index-partial/>`
0 commit comments