@@ -18,34 +18,34 @@ queries that span multiple collections.
1818``QuerySet.explain() ``
1919======================
2020
21- - :meth: `QuerySet.explain() <django.db.models.query.QuerySet.explain> ` supports
22- the `comment and verbosity options
23- <https://www.mongodb.com/docs/manual/reference/command/explain/#command-fields> `_.
21+ :meth: `QuerySet.explain() <django.db.models.query.QuerySet.explain> ` supports
22+ the `comment and verbosity options
23+ <https://www.mongodb.com/docs/manual/reference/command/explain/#command-fields> `_.
2424
25- Example::
25+ Example::
2626
27- Model.objects.explain(comment="...", verbosity="...")
27+ Model.objects.explain(comment="...", verbosity="...")
2828
29- Valid values for ``verbosity `` are ``"queryPlanner" `` (default),
30- ``"executionStats" ``, and ``"allPlansExecution" ``.
29+ Valid values for ``verbosity `` are ``"queryPlanner" `` (default),
30+ ``"executionStats" ``, and ``"allPlansExecution" ``.
3131
3232MongoDB-specific ``QuerySet `` methods
3333=====================================
3434
3535.. class :: django_mongodb_backend.managers.MongoManager
3636
37- Some MongoDB-specific ``QuerySet `` methods are available by adding a custom
38- :class: `~django.db.models.Manager `, ``MongoManager ``, to your model::
37+ Some MongoDB-specific ``QuerySet `` methods are available by adding a custom
38+ :class: `~django.db.models.Manager `, ``MongoManager ``, to your model::
3939
40- from django.db import models
40+ from django.db import models
4141
42- from django_mongodb_backend.managers import MongoManager
42+ from django_mongodb_backend.managers import MongoManager
4343
4444
45- class MyModel(models.Model):
46- ...
45+ class MyModel(models.Model):
46+ ...
4747
48- objects = MongoManager()
48+ objects = MongoManager()
4949
5050
5151.. currentmodule :: django_mongodb_backend.queryset.MongoQuerySet
@@ -55,48 +55,48 @@ Some MongoDB-specific ``QuerySet`` methods are available by adding a custom
5555
5656.. method :: raw_aggregate(pipeline, using=None)
5757
58- Similar to :meth: `QuerySet.raw()<django.db.models.query.QuerySet.raw> `, but
59- instead of a raw SQL query, this method accepts a pipeline that will be passed
60- to :meth: `pymongo.collection.Collection.aggregate `.
61-
62- For example, you could write a custom match criteria::
63-
64- Question.objects.raw_aggregate([{"$match": {"question_text": "What's up"}}])
65-
66- The pipeline may also return additional fields that will be added as
67- annotations on the models::
68-
69- >>> questions = Question.objects.raw_aggregate([{
70- ... "$project": {
71- ... "question_text": 1,
72- ... "pub_date": 1,
73- ... "year_published": {"$year": "$pub_date"}
74- ... }
75- ... }])
76- >>> for q in questions:
77- ... print(f"{q.question_text} was published in {q.year_published}.")
78- ...
79- What's up? was published in 2024.
80-
81- Fields may also be left out:
82-
83- >>> Question.objects.raw_aggregate([{" $project" : {" question_text" : 1 }}])
84-
85- The ``Question `` objects returned by this query will be deferred model instances
86- (see :meth: `~django.db.models.query.QuerySet.defer() `). This means that the
87- fields that are omitted from the query will be loaded on demand. For example::
88-
89- >>> for q in Question.objects.raw_aggregate([{"$project": {"question_text": 1}}]):
90- >>> print(
91- ... q.question_text, # This will be retrieved by the original query.
92- ... q.pub_date, # This will be retrieved on demand.
93- ... )
94- ...
95- What's new 2023-09-03 12:00:00+00:00
96- What's up 2024-08-23 20:57:30+00:00
97-
98- From outward appearances, this looks like the query has retrieved both the
99- question text and published date. However, this example actually issued three
100- queries. Only the question texts were retrieved by the ``raw_aggregate() ``
101- query -- the published dates were both retrieved on demand when they were
102- printed.
58+ Similar to :meth: `QuerySet.raw()<django.db.models.query.QuerySet.raw> `, but
59+ instead of a raw SQL query, this method accepts a pipeline that will be passed
60+ to :meth: `pymongo.collection.Collection.aggregate `.
61+
62+ For example, you could write a custom match criteria::
63+
64+ Question.objects.raw_aggregate([{"$match": {"question_text": "What's up"}}])
65+
66+ The pipeline may also return additional fields that will be added as
67+ annotations on the models::
68+
69+ >>> questions = Question.objects.raw_aggregate([{
70+ ... "$project": {
71+ ... "question_text": 1,
72+ ... "pub_date": 1,
73+ ... "year_published": {"$year": "$pub_date"}
74+ ... }
75+ ... }])
76+ >>> for q in questions:
77+ ... print(f"{q.question_text} was published in {q.year_published}.")
78+ ...
79+ What's up? was published in 2024.
80+
81+ Fields may also be left out:
82+
83+ >>> Question.objects.raw_aggregate([{" $project" : {" question_text" : 1 }}])
84+
85+ The ``Question `` objects returned by this query will be deferred model instances
86+ (see :meth: `~django.db.models.query.QuerySet.defer() `). This means that the
87+ fields that are omitted from the query will be loaded on demand. For example::
88+
89+ >>> for q in Question.objects.raw_aggregate([{"$project": {"question_text": 1}}]):
90+ >>> print(
91+ ... q.question_text, # This will be retrieved by the original query.
92+ ... q.pub_date, # This will be retrieved on demand.
93+ ... )
94+ ...
95+ What's new 2023-09-03 12:00:00+00:00
96+ What's up 2024-08-23 20:57:30+00:00
97+
98+ From outward appearances, this looks like the query has retrieved both the
99+ question text and published date. However, this example actually issued three
100+ queries. Only the question texts were retrieved by the ``raw_aggregate() ``
101+ query -- the published dates were both retrieved on demand when they were
102+ printed.
0 commit comments