Skip to content

Commit a1f6613

Browse files
committed
feedback
1 parent 0c4d8ed commit a1f6613

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

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

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ the ``QuerySet`` API:
9696
- :ref:`filter() <django-query-retrieve-matching>`
9797
- :ref:`get() <django-query-retrieve-one>`
9898
- :ref:`exclude() <django-query-exclude>`
99+
- :ref:`raw_aggregate() <django-query-raw>`
99100

100101
.. _django-query-retrieve-all:
101102

@@ -235,6 +236,20 @@ exclude documents released before January 1, 1980 from the results:
235236
lookups, see the :ref:`django-query-comparison` section
236237
in this guide.
237238

239+
.. _django-query-raw:
240+
241+
Run Raw Database Queries
242+
~~~~~~~~~~~~~~~~~~~~~~~~
243+
244+
If you want to run complex queries that Django's query API
245+
cannot express, you can use the ``raw_aggregate()`` method. This
246+
method allows you to specify your query criteria in a MongoDB
247+
aggregation pipeline, which you pass as an argument to
248+
``raw_aggregate()``.
249+
250+
To learn how to run raw database queries, see the :ref:`django-raw-queries`
251+
guide.
252+
238253
Customize Your Query Filter
239254
---------------------------
240255

@@ -399,25 +414,32 @@ is less than or equal to ``50``:
399414
Combine Lookups
400415
~~~~~~~~~~~~~~~
401416

417+
You can run queries that use multiple sets of matching criteria
418+
in the following ways:
419+
420+
- Pass multiple query filters to your query method, separated
421+
by commas. To view an example, see `Retrieving objects
422+
<{+django-docs+}/topics/db/queries/#retrieving-objects>`__ in the
423+
Django documentation.
424+
425+
- Chain query methods together. To learn more, see `Chaining filters
426+
<{+django-docs+}/topics/db/queries/#chaining-filters>`__ in the Django
427+
documentation.
428+
429+
- Use ``Q`` objects and separate each object with a logical operator.
430+
To learn more, see `Complex lookups with Q objects
431+
<{+django-docs+}/topics/db/queries/#complex-lookups-with-q-objects>`__ in the Django
432+
documentation.
433+
434+
Q Object Example
435+
````````````````
436+
402437
You can use ``Q`` objects to run queries with multiple
403438
sets of matching criteria. To create a ``Q`` object, pass your query
404439
filter to the ``Q()`` method. You can pass multiple ``Q`` objects as
405440
arguments to your query method and separate each ``Q`` object by an OR
406441
(``|``), AND (``&``), or XOR (``^``) operator. You can also negate
407-
``Q`` objects by prefixing them with the ``~`` symbol. The following example
408-
shows the syntax for passing multiple ``Q`` objects to the ``filter()``
409-
method:
410-
411-
412-
.. code-block:: python
413-
:copyable: false
414-
415-
Model.objects.filter(
416-
Q(<field>__<lookup type>=<value>) <operator> Q(<field>__<lookup type>=<value>)
417-
)
418-
419-
Example
420-
```````
442+
``Q`` objects by prefixing them with the ``~`` symbol.
421443

422444
This example uses ``Q`` objects to query for documents
423445
that meet the following query conditions:

0 commit comments

Comments
 (0)