Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Django
Search
flaper87
April 24, 2012
6
710
Django
flaper87
April 24, 2012
Tweet
Share
More Decks by flaper87
See All by flaper87
Inheriting code… and I don’t mean classes
flaper87
0
240
Don't try to look smart, be smart
flaper87
0
170
Keeping up with the pace of a fast growing community without dying
flaper87
0
180
A walk to remember: Debugging a distributed system failure
flaper87
0
200
Managing requirements for a many-thousands contributors software
flaper87
0
89
Fast-forward to today's Zaqar
flaper87
0
130
Breaking Backwards Compatibility: The easy way
flaper87
1
160
A functional view to Rust
flaper87
1
140
Rust - A walk to concurrency
flaper87
3
580
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Facilitating Awesome Meetings
lara
54
6.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Git: the NoSQL Database
bkeepers
PRO
430
65k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Invisible Side of Design
smashingmag
299
51k
Scaling GitHub
holman
459
140k
KATA
mclloyd
29
14k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Transcript
So you want to use DJANGO AND MONGODB @flaper87
THAT’S COOL, but you n d to know A COUPLE
OF THINGS DJANGO AND MONGODB
LIKE: WHAT ARE THE OPTIONS?
An object-document mapper to connect Python and MongoDB ( http://mongoengine.org
)
Another ODM that takes mongodb into the web Mongokit (
http://namlook.github.com/mongokit/ )
OR, OF COURSE
DJANGO MONGODB ENGINE (A MongoDB backend for Django)
DJANGO-NONREL A good and up to date Django fork that
brings non-rel support
django.contrib.* Sadly, some of your may be broken, but not
the admin
erm... OKAY WHAT’S SO COOL ABOUT THIS THEN?
No anges n ded. WHAT’S SO COOL ABOUT THIS THEN?
No anges n ded. NOBODY’S GONNA TOUCH YOUR PRECIOUS BUILTINS.
ABOUT THIS THEN?
NOBODY’S GONNA TOUCH YOUR PRECIOUS BUILTINS. REDUCED IMPEDANCE MISSMATCH
WHAT ELSE? at’s c l
NEW FIELDS
AGGREGATIONS
GRIDFS
CACHING
MAP / REDUCE >>> for pair in Article.objects.map_reduce(_map, _reduce, 'wordcount'):
... print pair.key, pair.value
NEW INDEXES class Club(models.Model): location = ListField() rating = models.FloatField()
... class MongoMeta: indexes = [ [('rating', -1)], {'fields': [('location', '2d')], 'min': -42, 'max': 42}, ]
TONS OF DOCS Plus: (which never hurts)
Su estions
RAW QUERIES MyModel.objects.raw_query(field=“value”)
EMBEDD IF POSSIBLE class Comment(models.Model): created_on = models.DateTimeField() author =
EmbeddedModelField('Author') text = models.TextField()
RE-THINK YOUR MODELS class Post(models.Model): title = models.CharField() text =
models.TextField() tags = ListField() # Note: Use defer comments = ListField(EmbeddedModelField('Comment'))
DO NOT USE IT EVERYWHERE MONGODB_MANAGED_APPS = ['myapp'] MONGODB_MANAGED_MODELS =
['myapp.MongoDBModel']
SERVE STATIC FILES GridFSStorage + nginx-GridFS
AGGREGATIONS? MAP/REDUCE class Min(MongoAggregate): initial_value = float('inf') reduce_template = '{alias}
= ({lookup}<{alias})?{lookup}:{alias}' class Max(MongoAggregate): initial_value = float('-inf') reduce_template = '{alias} = ({lookup}>{alias})?{lookup}:{alias}'
DATES WORK But, MongoDB does not support month/day queries
DO NOT TRY TO MIGRATE It Wont Work!
CONTRIBUTE The Compiler’s a mess
A away Contribute: http://django-mongodb.org /meta/contributing.html http://groups.google.com /group/django-non-relational