@@ -96,6 +96,7 @@ the ``QuerySet`` API:
96
96
- :ref:`filter() <django-query-retrieve-matching>`
97
97
- :ref:`get() <django-query-retrieve-one>`
98
98
- :ref:`exclude() <django-query-exclude>`
99
+ - :ref:`raw_aggregate() <django-query-raw>`
99
100
100
101
.. _django-query-retrieve-all:
101
102
@@ -235,6 +236,20 @@ exclude documents released before January 1, 1980 from the results:
235
236
lookups, see the :ref:`django-query-comparison` section
236
237
in this guide.
237
238
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
+
238
253
Customize Your Query Filter
239
254
---------------------------
240
255
@@ -399,25 +414,32 @@ is less than or equal to ``50``:
399
414
Combine Lookups
400
415
~~~~~~~~~~~~~~~
401
416
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
+
402
437
You can use ``Q`` objects to run queries with multiple
403
438
sets of matching criteria. To create a ``Q`` object, pass your query
404
439
filter to the ``Q()`` method. You can pass multiple ``Q`` objects as
405
440
arguments to your query method and separate each ``Q`` object by an OR
406
441
(``|``), 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.
421
443
422
444
This example uses ``Q`` objects to query for documents
423
445
that meet the following query conditions:
0 commit comments