Skip to content
10 changes: 7 additions & 3 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ intersphinx = [ "https://www.mongodb.com/docs/manual/objects.inv",
"https://www.mongodb.com/docs/atlas/objects.inv"
]

# toc_landing_pages = ["/paths/to/pages/that/have/nested/content"]
toc_landing_pages = [
"/interact-data"
]

# [constants]
# constant = "value"
[constants]
django-odm = "Django MongoDB Backend"
django-api = "https://django-mongodb.readthedocs.io/en/latest/"
mdb-server = "MongoDB Server"
106 changes: 106 additions & 0 deletions source/includes/interact-data/raw-queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# start-models
from django.db import models
from django_mongodb_backend.fields import ArrayField
from django_mongodb_backend.managers import MongoManager

class Movie(models.Model):
title = models.CharField(max_length=200)
plot = models.TextField(blank=True)
runtime = models.IntegerField(default=0)
released = models.DateTimeField("release date", null=True, blank=True)
genres = ArrayField(models.CharField(max_length=100), null=True, blank=True)
objects = MongoManager()

class Meta:
db_table = "movies"
managed = False

def __str__(self):
return self.title

class Theater(models.Model):
theaterId = models.IntegerField(default=0)
objects = MongoManager()

class Meta:
db_table = "theaters"
managed = False

def __str__(self):
return self.title
# end-models

# start-filter-project
from sample_mflix.models import Movie

movies = Movie.objects.raw_aggregate([
{"$match": {"title": "The Parent Trap"}},
{"$project": {
"title": 1,
"released": 1
}
}])

for m in movies:
print(f"Plot of {m.title}, released on {m.released}: {m.plot}\n")
# end-filter-project

# start-atlas-search
movies = Movie.objects.raw_aggregate([
{
"$search": {
"index": "<search-index-name>",
"phrase": {
"path": "plot",
"query": "whirlwind romance",
"slop": 3
},
"highlight": {
"path": "plot"
}
}
},
{
"$project": {
"title": 1,
"highlight": {"$meta": "searchHighlights"}
}
}
])

for m in movies:
print(f"Title: {m.title}, text match details: {m.highlight}\n")
# end-atlas-search

# start-geo
chicago_bounds = {
"type": "Polygon",
"coordinates": [[
[-87.851, 41.976],
[-87.851, 41.653],
[-87.651, 41.653],
[-87.651, 41.976],
[-87.851, 41.976]
]]
}

theaters = Theater.objects.raw_aggregate([
{
"$match": {
"location.geo": {
"$geoWithin": {
"$geometry": chicago_bounds
}
}
}
},
{
"$project": {
"theaterId": 1
}
}
])

for t in theaters:
print(f"Theater ID: {t.theaterId}")
# end-geo
19 changes: 16 additions & 3 deletions source/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
Django MongoDB Backend
======================

.. default-domain:: mongodb
.. facet::
:name: programming_language
:values: python

Your words here. Don't forget to add a toctree!
.. meta::
:keywords: home

Have a lovely day!
.. toctree::

Interact with Data </interact-data>

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

Interact with Data
------------------

Learn how to use {+ddjango-odm+} to perform operations on MongoDB data
in the :ref:`django-interact-data` section.
17 changes: 17 additions & 0 deletions source/interact-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _django-interact-data:

==================
Interact with Data
==================

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: odm, crud, query

.. toctree::
:caption: Interact with Data

Perform Raw Queries </interact-data/raw-queries>
Loading