Django Mongodb Engine

2,268
-1

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,268
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
30
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Django Mongodb Engine

  1. 1. So you want to useDJANGO ANDMONGODB @flaper87
  2. 2. DJANGO AND MONGODB THAT’S COOL, but you needto know A COUPLE OF THINGS
  3. 3. LIKE: WHAT ARETHE OPTIONS?
  4. 4. ( http://mongoengine.org ) An object-document mapperto connect Python and MongoDB
  5. 5. Mongokit ( http://namlook.github.com/mongokit/ ) Another ODMthat takes mongodb into the web
  6. 6. OR, OF COURSE
  7. 7. DJANGOMONGODBENGINE(A MongoDB backend for Django)
  8. 8. DJANGO-NONRELA good and up to date Django fork that brings non-rel support
  9. 9. Sadly, some of yourdjango.contrib.*may be broken, but not the admin
  10. 10. erm...
  11. 11. erm... OKAY WHAT’S SO COOLABOUT THIS THEN?
  12. 12. WHAT’S SO COOLABOUT THIS THEN? No changes needed.
  13. 13. ABOUT THIS THEN? No changes needed. NOBODY’S GONNA TOUCH YOUR PRECIOUS BUILTINS.
  14. 14. NOBODY’S GONNA TOUCH YOUR PRECIOUS BUILTINS.REDUCED IMPEDANCE MISSMATCH
  15. 15. That’s coolWHAT ELSE?
  16. 16. NEW FIELDS
  17. 17. AGGREGATIONS
  18. 18. GRIDFS
  19. 19. CACHING
  20. 20. MAP / REDUCE>>> for pair in Article.objects.map_reduce(_map, _reduce, wordcount):... print pair.key, pair.value
  21. 21. NEW INDEXESclass Club(models.Model): location = ListField() rating = models.FloatField() ... class MongoMeta: indexes = [ [(rating, -1)], {fields: [(location, 2d)], min: -42, max: 42}, ]
  22. 22. Plus:TONS OF DOCS (which never hurts)
  23. 23. Suggestions
  24. 24. RAW QUERIESMyModel.objects.raw_query(field=“value”)
  25. 25. EMBEDD IF POSSIBLEclass Comment(models.Model): created_on = models.DateTimeField() author = EmbeddedModelField(Author) text = models.TextField()
  26. 26. RE-THINK YOUR MODELSclass Post(models.Model): title = models.CharField() text = models.TextField() tags = ListField() # Note: Use defer comments = ListField(EmbeddedModelField(Comment))
  27. 27. DO NOT USE IT EVERYWHEREMONGODB_MANAGED_APPS = [myapp]MONGODB_MANAGED_MODELS = [myapp.MongoDBModel]
  28. 28. SERVE STATIC FILESGridFSStorage + nginx-GridFS
  29. 29. AGGREGATIONS? MAP/REDUCEclass 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}
  30. 30. DATES WORK But, MongoDBdoes not support month/day queries
  31. 31. DO NOT TRYTO MIGRATEIt Wont Work!
  32. 32. CONTRIBUTEThe Compiler’s a mess
  33. 33. Ask away http://groups.google.com/group/django-non-relational Contribute:http://django-mongodb.org /meta/contributing.html
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×