@@ -25,10 +25,10 @@ raw queries on your MongoDB database. Raw queries allow you to
2525query the database by using MongoDB's aggregation pipeline syntax
2626rather than Django methods.
2727
28- The Django ``QuerySet`` API provides a ``QuerySet. raw()`` method, which allows
28+ The Django ``QuerySet`` API provides a ``raw()`` method, which allows
2929you to perform raw SQL queries on relational databases. However, {+django-odm+}
3030does not support the ``raw()`` method. Instead, the ODM provides the
31- ``QuerySet. raw_aggregate()`` method, which you can use to send instructions
31+ ``raw_aggregate()`` method, which you can use to send instructions
3232to the database in pipeline stages.
3333
3434.. note::
@@ -39,12 +39,22 @@ to the database in pipeline stages.
3939 the ``aggregate()`` method, see `Aggregation <{+django-docs+}/topics/db/aggregation/>`__
4040 in the Django documentation.
4141
42+ You can run database queries by calling ``QuerySet`` methods on your model's
43+ ``Manager``. The ``Manager`` class handles database operations and allows you
44+ to interact with your MongoDB data by referencing Django models. By default,
45+ Django adds a ``Manager`` named ``objects`` to every model class. This default
46+ ``Manager`` does not support the ``raw_aggregate()`` method. To use this
47+ MongoDB-specific method, set your model's ``objects`` field to a custom
48+ manager called ``MongoManager``.
49+
4250Sample Data
4351~~~~~~~~~~~
4452
4553The examples in this guide use the ``Movie`` and ``Theater`` models, which
4654represent collections in the ``sample_mflix`` database from the :atlas:`Atlas sample datasets </sample-data>`.
47- The model classes have the following definitions:
55+ The ``Movie`` model explicitly sets the ``objects`` field to use a custom ``MongoManager``,
56+ rather than Django's default ``Manager`` class. The model classes have the following
57+ definitions:
4858
4959.. literalinclude:: /includes/interact-data/raw-queries.py
5060 :start-after: start-models
@@ -62,7 +72,7 @@ Run Raw Queries
6272---------------
6373
6474To run a raw database query, pass an aggregation pipeline
65- to the ``QuerySet. raw_aggregate()`` method. Aggregation pipelines
75+ to the ``raw_aggregate()`` method. Aggregation pipelines
6676contain one or more stages that provide instructions on how to
6777process documents. After calling the ``raw_aggregate()`` method,
6878{+django-odm+} passes your pipeline to the ``pymongo.collection.Collection.aggregate()``
@@ -87,10 +97,9 @@ Filter and Project Document Fields
8797~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8898
8999This example runs a raw database query by calling the
90- ``raw_aggregate()`` method on your ``Movie`` objects,
91- which represent documents in the ``sample_mflix.movies``
92- collection. The code passes the following aggregation pipeline stages
93- to ``raw_aggregate()``:
100+ ``raw_aggregate()`` method on your ``Movie`` model's ``MongoManager``,
101+ which queries the ``sample_mflix.movies`` collection. The code
102+ passes the following aggregation pipeline stages to ``raw_aggregate()``:
94103
95104- ``$match``: Filters for documents that have a ``title``
96105 field value of ``"The Parent Trap"``
0 commit comments