Skip to content

Commit e4d6a91

Browse files
committed
Merge remote-tracking branch 'upstream/master' into DOCSP-46320-landing-pages
2 parents e071a07 + a6d9814 commit e4d6a91

File tree

5 files changed

+491
-4
lines changed

5 files changed

+491
-4
lines changed

snooty.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ toc_landing_pages = [
1313

1414
[constants]
1515
django-odm = "Django MongoDB Backend"
16-
api = "https://django-mongodb.readthedocs.io/en/latest/"
16+
api = "https://django-mongodb-backend.readthedocs.io/en/latest/"
1717
mdb-server = "MongoDB Server"
1818
django-version = "5.0"
1919
django-docs = "https://docs.djangoproject.com/en/{+django-version+}"
2020
framework = "Django"
21+
pymongo-docs = "https://www.mongodb.com/docs/languages/python/pymongo-driver/current"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# start-models
2+
from django.db import models
3+
from django_mongodb_backend.fields import ArrayField
4+
from django_mongodb_backend.managers import MongoManager
5+
6+
class Movie(models.Model):
7+
title = models.CharField(max_length=200)
8+
plot = models.TextField(blank=True)
9+
runtime = models.IntegerField(default=0)
10+
released = models.DateTimeField("release date", null=True, blank=True)
11+
genres = ArrayField(models.CharField(max_length=100), null=True, blank=True)
12+
objects = MongoManager()
13+
14+
class Meta:
15+
db_table = "movies"
16+
managed = False
17+
18+
def __str__(self):
19+
return self.title
20+
21+
class Theater(models.Model):
22+
theaterId = models.IntegerField(default=0)
23+
objects = MongoManager()
24+
25+
class Meta:
26+
db_table = "theaters"
27+
managed = False
28+
29+
def __str__(self):
30+
return self.theaterId
31+
# end-models
32+
33+
# start-filter-project
34+
movies = Movie.objects.raw_aggregate([
35+
{"$match": {"title": "The Parent Trap"}},
36+
{"$project": {
37+
"title": 1,
38+
"released": 1
39+
}
40+
}])
41+
42+
for m in movies:
43+
print(f"Plot of {m.title}, released on {m.released}: {m.plot}\n")
44+
# end-filter-project
45+
46+
# start-atlas-search
47+
movies = Movie.objects.raw_aggregate([
48+
{
49+
"$search": {
50+
"index": "<search-index-name>",
51+
"phrase": {
52+
"path": "plot",
53+
"query": "whirlwind romance",
54+
"slop": 3
55+
},
56+
"highlight": {
57+
"path": "plot"
58+
}
59+
}
60+
},
61+
{
62+
"$project": {
63+
"title": 1,
64+
"highlight": {"$meta": "searchHighlights"}
65+
}
66+
}
67+
])
68+
69+
for m in movies:
70+
print(f"Title: {m.title}, text match details: {m.highlight}\n")
71+
# end-atlas-search
72+
73+
# start-geo
74+
chicago_bounds = {
75+
"type": "Polygon",
76+
"coordinates": [[
77+
[-87.851, 41.976],
78+
[-87.851, 41.653],
79+
[-87.651, 41.653],
80+
[-87.651, 41.976],
81+
[-87.851, 41.976]
82+
]]
83+
}
84+
85+
theaters = Theater.objects.raw_aggregate([
86+
{
87+
"$match": {
88+
"location.geo": {
89+
"$geoWithin": {
90+
"$geometry": chicago_bounds
91+
}
92+
}
93+
}
94+
},
95+
{
96+
"$project": {
97+
"theaterId": 1
98+
}
99+
}
100+
])
101+
102+
for t in theaters:
103+
print(f"Theater ID: {t.theaterId}")
104+
# end-geo

source/includes/use-sample-data.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The |model-classes| an inner ``Meta`` class, which specifies
2+
model metadata, and a ``__str__()`` method, which defines the
3+
model's string representation. To learn about these
4+
model features, see :ref:`django-models-define` in the
5+
Create Models guide.
6+
7+
Run Code Examples
8+
`````````````````
9+
10+
You can use the Python interactive shell to run the code examples.
11+
To enter the shell, run the following command from your project's
12+
root directory:
13+
14+
.. code-block:: bash
15+
16+
python manage.py shell
17+
18+
After entering the Python shell, ensure that you import the following models and
19+
modules:
20+
21+
|model-imports|
22+
23+
To learn how to create a {+framework+} application that uses the ``Movie``
24+
model and the Python interactive shell to interact with MongoDB documents,
25+
visit the :ref:`django-get-started` tutorial.

source/index.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@ Django MongoDB Backend
1515
Interact with Data </interact-data>
1616
Issues & Help </issues-and-help>
1717
Compatibility </compatibility>
18+
API Documentation <{+api+}>
1819

1920

2021
.. TODO:
2122
Get Started </get-started>
2223
Connection Configuration </connect>
23-
24-
2524
Django Feature Limitations </feature-limitations>
26-
API Documentation <{+api+}>
2725

2826
Introduction
2927
------------
3028

3129
Welcome to the documentation site for the official {+django-odm+},
3230
a Django database backend that uses PyMongo to connect to MongoDB.
3331

32+
Interact with Data
33+
------------------
34+
35+
Learn how to use {+django-odm+} to perform operations on MongoDB data
36+
in the :ref:`django-interact-data` section.
37+
3438
.. TODO:
3539

3640
.. Get Started

0 commit comments

Comments
 (0)