Skip to content

Commit d746448

Browse files
committed
clarify
1 parent ea6b1b3 commit d746448

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

source/includes/model-data/indexes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ class Meta:
7676
# start-unique-compound
7777
class Meta:
7878
db_table = "recipes"
79-
indexes = [
80-
models.Index(fields=["title", "cuisine"]),
81-
]
8279
constraints = [
8380
models.UniqueConstraint(fields=["title", "cuisine"],
8481
name="unique_regional_meal"),
@@ -89,7 +86,7 @@ class Meta:
8986
class Meta:
9087
db_table = "recipes"
9188
indexes = [
92-
models.Index(F("cook_time") + F("prep_time"),
89+
models.Index(expressions=F("cook_time") + F("prep_time"),
9390
name="total_time_idx"),
9491
]
9592
# end-expression

source/model-data/indexes.txt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ Overview
2121
--------
2222

2323
In this guide, you can learn how to create MongoDB **indexes** by using your
24-
Django models. Indexes can improve the efficiency of queries and add
24+
Django models. Indexes can improve the efficiency of queries and provide
2525
additional query and document storage functionality.
2626

2727
Without indexes, MongoDB must scan every document in a collection to find the
28-
documents that match each query. These collection scans are
29-
slow and can negatively affect the performance of your application. However, if an
28+
documents that match a query. These collection scans are slow and can
29+
negatively affect the performance of your application. However, if an
3030
appropriate index exists for a query, MongoDB can use the index to limit the
3131
documents it inspects.
3232

@@ -53,10 +53,11 @@ These model classes have the following definitions:
5353
:language: python
5454
:copyable:
5555

56-
The ``db_table = "recipes"`` option instructs {+django-odm+} to map the ``Recipe``
57-
model to a MongoDB collection called ``recipes``. To learn how to
58-
create a Django application that uses models to interact with MongoDB
59-
collections, visit the :ref:`django-get-started` tutorial.
56+
In the ``Recipe`` model's ``Meta`` class, the ``db_table = "recipes"`` option
57+
instructs {+django-odm+} to map the ``Recipe`` model to a MongoDB collection
58+
called ``recipes``. To learn how to create a Django application that
59+
uses models to interact with MongoDB collections, visit the
60+
:ref:`django-get-started` tutorial.
6061

6162
Create an Index
6263
---------------
@@ -80,7 +81,7 @@ To define your index, pass the following arguments to the ``models.Index()`` met
8081

8182
- ``expressions``: Specifies a database expression to index. If you don't pass
8283
the ``fields`` argument, this argument is required. To learn more about this
83-
argument, see the :ref:`django-indexes-functions` section of this guide.
84+
argument, see the :ref:`django-indexes-expressions` section of this guide.
8485

8586
- ``fields``: Specifies a list of fields to index. If you don't pass the
8687
``expressions`` argument, this argument is required.
@@ -203,7 +204,7 @@ index types:
203204

204205
- :ref:`django-indexes-partial`
205206
- :ref:`django-indexes-unique`
206-
- :ref:`django-indexes-functions`
207+
- :ref:`django-indexes-expressions`
207208

208209
.. _django-indexes-partial:
209210

@@ -266,7 +267,7 @@ Compound Example
266267
````````````````
267268

268269
The following example updates the ``Recipe`` model's ``Meta`` class to create
269-
a compound index on the ``title`` and ``cuisine`` fields. Then, the code
270+
a compound index on the ``title`` and ``cuisine`` fields. The code
270271
sets the ``constraints`` option to a ``UniqueConstraint`` instance, which
271272
creates a unique compound index on these fields:
272273

@@ -275,17 +276,19 @@ creates a unique compound index on these fields:
275276
:end-before: end-unique-compound
276277
:language: python
277278
:copyable:
278-
:emphasize-lines: 6-8
279+
:emphasize-lines: 3-6
279280

280281
.. tip::
281282

282-
To learn more about the ``Meta`` class's ``constraint`` option, see `Constraints
283-
<{+django-docs+}/ref/models/constraints/>`__ in the Django documentation.
283+
Setting the ``constraints`` option to a ``UniqueConstraint`` automatically
284+
creates an index on the specified fields. To learn more about the ``Meta``
285+
class's ``constraint`` option, see `Constraints <{+django-docs+}/ref/models/constraints/>`__
286+
in the Django documentation.
284287

285-
.. _django-indexes-functions:
288+
.. _django-indexes-expressions:
286289

287-
Function Indexes
288-
~~~~~~~~~~~~~~~~
290+
Expression Indexes
291+
~~~~~~~~~~~~~~~~~~
289292

290293
To create indexes on expressions and database functions, pass the
291294
``expressions`` argument to the ``models.Index()`` method. When using

0 commit comments

Comments
 (0)