Skip to content

Commit d775baf

Browse files
committed
edits
1 parent a29716e commit d775baf

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

source/interact-data/specify-a-query.txt

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ In this guide, you can learn how to use {+django-odm+} to specify
2424
a database query.
2525

2626
The Django ``QuerySet`` API provides functions that allow you to retrieve
27-
model objects. To run a MongoDB database query, create a ``QuerySet`` object
28-
that specifies your query and the model you're querying. Then, {+django-odm+}
29-
runs the operation on the MongoDB collection that the model represents.
27+
model objects. To run a MongoDB database query, call ``QuerySet`` functions
28+
on your model's ``Manager``. The ``Manager`` class handles database
29+
operations and allows you to interact with your MongoDB data by referencing
30+
Django models. By default, Django adds a ``Manager`` named ``objects``
31+
to every model class.
3032

31-
When you assign a ``QuerySet`` object to a variable, {+django-odm+} does not
33+
When you assign a ``QuerySet`` to a variable, {+django-odm+} does not
3234
perform the operation until you evaluate the variable, usually by printing. After
3335
evaluating the ``QuerySet``, Django saves the query results in the ``QuerySet``
3436
cache. Future evaluations of the ``QuerySet`` reuse the cached results.
@@ -83,9 +85,9 @@ visit the :ref:`django-get-started` tutorial.
8385
Run a Query
8486
-----------
8587

86-
To query your MongoDB data, call a ``QuerySet`` function on the
87-
model that represents your collection and specify your matching
88-
criteria in a query filter.
88+
To query your MongoDB data, call a ``QuerySet`` function on your
89+
model's ``Manager`` class and specify your matching criteria in a
90+
query filter.
8991

9092
This section describes how to use the following functions from
9193
the ``QuerySet`` API:
@@ -101,11 +103,10 @@ Retrieve All Documents
101103
~~~~~~~~~~~~~~~~~~~~~~
102104

103105
To retrieve all documents from a collection, call the ``all()``
104-
function on the collection's corresponding Django model.
106+
function on your model's ``Manager`` class.
105107

106-
The following example calls the ``all()`` function on the
107-
``Movie`` model to retrieve all documents in the ``sample_mflix.movies``
108-
collection:
108+
The following example calls the ``all()`` function to retrieve
109+
all documents in the ``sample_mflix.movies`` collection:
109110

110111
.. io-code-block::
111112
:copyable:
@@ -135,12 +136,12 @@ Retrieve Matching Documents
135136
~~~~~~~~~~~~~~~~~~~~~~~~~~~
136137

137138
To query a collection for documents that match a set of criteria,
138-
call the ``filter()`` function on the collection's corresponding Django
139-
model. Pass a query filter to the ``filter()`` function that specifies your
139+
call the ``filter()`` function on your model's ``Manager`` class.
140+
Pass a query filter to the ``filter()`` function that specifies your
140141
query criteria.
141142

142-
The following example calls the ``filter()`` function on the
143-
``Movie`` model to query the ``sample_mflix.movies`` collection
143+
The following example calls the ``filter()`` function
144+
to query the ``sample_mflix.movies`` collection
144145
for documents that have a ``runtime`` value of ``300``:
145146

146147
.. io-code-block::
@@ -163,7 +164,7 @@ Retrieve One Document
163164
~~~~~~~~~~~~~~~~~~~~~
164165

165166
To retrieve one document from a collection, call the ``get()``
166-
function on the collection's corresponding Django model. Pass
167+
function on your model's ``Manager`` class. Pass
167168
a query filter to the ``get()`` function that specifies your
168169
query criteria.
169170

@@ -175,8 +176,8 @@ query criteria.
175176
function.
176177

177178

178-
The following example calls the ``get()`` function on the
179-
``Movie`` model to retrieve one document that has a ``title``
179+
The following example calls the ``get()`` function
180+
to retrieve one document that has a ``title``
180181
value of ``"Finding Nemo"``:
181182

182183
.. io-code-block::
@@ -198,13 +199,12 @@ Exclude Matching Documents
198199
~~~~~~~~~~~~~~~~~~~~~~~~~~
199200

200201
To query a collection for documents that do not meet your
201-
search criteria, call the ``exclude()`` function on the collection's
202-
corresponding Django model. Pass the exclusion criteria as an
202+
search criteria, call the ``exclude()`` function on your model's
203+
``Manager`` class. Pass the exclusion criteria as an
203204
argument to the ``exclude()`` function.
204205

205-
The following example calls the ``exclude()`` function on the
206-
``Movie`` model to exclude documents released before January 1,
207-
1980 from the results:
206+
The following example calls the ``exclude()`` function to
207+
exclude documents released before January 1, 1980 from the results:
208208

209209
.. io-code-block::
210210
:copyable:
@@ -498,7 +498,7 @@ Example
498498

499499
This example performs the following actions:
500500

501-
- Calls the ``filter()`` function on the ``Movie`` model to query
501+
- Calls the ``filter()`` function on the ``Movie`` model's ``Manager`` to query
502502
the ``sample_mflix.movies`` collection
503503
- Queries documents that have a ``title`` value starting
504504
with the text ``"Rocky"``
@@ -550,7 +550,7 @@ Example
550550

551551
This example performs the following actions:
552552

553-
- Calls the ``filter()`` function on the ``Movie`` model to query
553+
- Calls the ``filter()`` function on the ``Movie`` model's ``Manager`` to query
554554
the ``sample_mflix.movies`` collection
555555
- Queries documents that have a ``released`` value of
556556
``datetime(2010, 7, 16)`` (July 16, 2010)
@@ -579,10 +579,9 @@ multiple results, chain the ``first()`` function to the ``filter()``
579579
function. Pass a query filter to the ``filter()`` function that specifies your
580580
query criteria.
581581

582-
The following example calls the ``filter()`` and ``first()`` functions on the
583-
``Movie`` model to query the ``sample_mflix.movies`` collection
584-
for the first document in which the ``genres`` value is
585-
``["Crime", "Comedy"]``:
582+
The following example calls the ``filter()`` and ``first()`` functions
583+
to query the ``sample_mflix.movies`` collection for the first
584+
document in which the ``genres`` value is ``["Crime", "Comedy"]``:
586585

587586
.. io-code-block::
588587
:copyable:

0 commit comments

Comments
 (0)