Django mongodb -djangoday_

1,180 views

Published on

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

No Downloads
Views
Total views
1,180
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Django mongodb -djangoday_

  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... OKAY WHAT’S SO COOLABOUT THIS THEN?
  11. 11. WHAT’S SO COOLABOUT THIS THEN? No changes needed.
  12. 12. ABOUT THIS THEN? No changes needed. NOBODY’S GONNA TOUCH YOUR PRECIOUS BUILTINS.
  13. 13. NOBODY’S GONNA TOUCH YOUR PRECIOUS BUILTINS.REDUCED IMPEDANCE MISSMATCH
  14. 14. That’s coolWHAT ELSE?
  15. 15. NEW FIELDS
  16. 16. AGGREGATIONS
  17. 17. GRIDFS
  18. 18. CACHING
  19. 19. MAP / REDUCE>>> for pair in Article.objects.map_reduce(_map, _reduce, wordcount):... print pair.key, pair.value
  20. 20. NEW INDEXESclass Club(models.Model): location = ListField() rating = models.FloatField() ... class MongoMeta: indexes = [ [(rating, -1)], {fields: [(location, 2d)], min: -42, max: 42}, ]
  21. 21. Plus:TONS OF DOCS (which never hurts)
  22. 22. Suggestions
  23. 23. RAW QUERIESMyModel.objects.raw_query(field=“value”)
  24. 24. EMBEDD IF POSSIBLEclass Comment(models.Model): created_on = models.DateTimeField() author = EmbeddedModelField(Author) text = models.TextField()
  25. 25. RE-THINK YOUR MODELSclass Post(models.Model): title = models.CharField() text = models.TextField() tags = ListField() # Note: Use defer comments = ListField(EmbeddedModelField(Comment))
  26. 26. DO NOT USE IT EVERYWHEREMONGODB_MANAGED_APPS = [myapp]MONGODB_MANAGED_MODELS = [myapp.MongoDBModel]
  27. 27. SERVE STATIC FILESGridFSStorage + nginx-GridFS
  28. 28. 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}
  29. 29. DATES WORK But, MongoDBdoes not support month/day queries
  30. 30. DO NOT TRYTO MIGRATEIt Wont Work!
  31. 31. CONTRIBUTEThe Compiler’s a mess
  32. 32. Ask away http://groups.google.com/group/django-non-relational Contribute:http://django-mongodb.org /meta/contributing.html

×