@@ -21,12 +21,12 @@ Overview
21
21
--------
22
22
23
23
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
25
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
- 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
30
30
appropriate index exists for a query, MongoDB can use the index to limit the
31
31
documents it inspects.
32
32
@@ -53,10 +53,11 @@ These model classes have the following definitions:
53
53
:language: python
54
54
:copyable:
55
55
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.
60
61
61
62
Create an Index
62
63
---------------
@@ -80,7 +81,7 @@ To define your index, pass the following arguments to the ``models.Index()`` met
80
81
81
82
- ``expressions``: Specifies a database expression to index. If you don't pass
82
83
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.
84
85
85
86
- ``fields``: Specifies a list of fields to index. If you don't pass the
86
87
``expressions`` argument, this argument is required.
@@ -203,7 +204,7 @@ index types:
203
204
204
205
- :ref:`django-indexes-partial`
205
206
- :ref:`django-indexes-unique`
206
- - :ref:`django-indexes-functions `
207
+ - :ref:`django-indexes-expressions `
207
208
208
209
.. _django-indexes-partial:
209
210
@@ -266,7 +267,7 @@ Compound Example
266
267
````````````````
267
268
268
269
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
270
271
sets the ``constraints`` option to a ``UniqueConstraint`` instance, which
271
272
creates a unique compound index on these fields:
272
273
@@ -275,17 +276,19 @@ creates a unique compound index on these fields:
275
276
:end-before: end-unique-compound
276
277
:language: python
277
278
:copyable:
278
- :emphasize-lines: 6-8
279
+ :emphasize-lines: 3-6
279
280
280
281
.. tip::
281
282
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.
284
287
285
- .. _django-indexes-functions :
288
+ .. _django-indexes-expressions :
286
289
287
- Function Indexes
288
- ~~~~~~~~~~~~~~~~
290
+ Expression Indexes
291
+ ~~~~~~~~~~~~~~~~~~
289
292
290
293
To create indexes on expressions and database functions, pass the
291
294
``expressions`` argument to the ``models.Index()`` method. When using
0 commit comments