Django with Mongo using Mongoengine

11,107 views

Published on

Presentation for #donetskpy meetup on February 18th, 2012.

Published in: Technology

Django with Mongo using Mongoengine

  1. 1. Django with Mongo using Mongoengine Artem Dudarev#donetskpy, #cncdnua, February 2012
  2. 2. Other ways to use Mongo with DjangoWhich Python API should be used with Mongo DB andDjango? • PyMongo-- • Mongoengine-- • Django MongoDB Engine • MongoDB backend for Django-nonrel
  3. 3. Django
  4. 4. DjangoThe Web framework for perfectionists with deadlines.Using Django • Disqus • Many newspapers: Washington Post, Guardian, Lawrence.com.In Donetsk • Steelkiwi • MLSDev
  5. 5. MongoMongo (from "humongous") is a scalable,high-performance, open source NoSQL database.Using Mongo • Foursquare • CatchIn Donetsk •?
  6. 6. MongoengineMongoEngine is a Document-Object Mapper (think ORM,but for document databases) for working with MongoDBfrom Python.
  7. 7. Mongoengine examplefrom mongoengine import (Document, EmbeddedDocument, ListField, StringField, IntField)class Metadata(EmbeddedDocument): tags = ListField(StringField()) revisions = ListField(IntField())class WikiPage(Document): title = StringField(required=True) text = StringField() metadata = EmbeddedDocumentField(Metadata)
  8. 8. Mongoengine example (cont.)>>> page.title = “Hello, World!”>>> for page in WikiPage.objects:>>> print page.title
  9. 9. — Игорь Афонов, #cncdnua #32
  10. 10. «Делайте велосипеды, но то так, что бы хотелось на них ездить.» — Игорь Давыденко, #kyivpy #5
  11. 11. Tumblr • http://wearethe99percent.tumblr.com/ • http://dearphotograph.com/ • http://stockingisthenewplanking.com/ • http://dudarev.tumblr.com/
  12. 12. Tumblr (cont.)http://mashable.com/2011/11/14/tumblr-infographic/ • 35M tumblogs • 45% photos • Top 5 tags: GIF, LOL, Fashion, Art, Vintage • 218% growth (from June to June) • $800M valuation
  13. 13. Mumblr • Harry Marr - developer of Mongoengine • Mumblr - Tumblr cloneStarting with Python (virtualenv, pip)git clone https://github.com/hmarr/django-mumblr.git mumblrcd mumblrvirtualenv .source bin/activatepip install -r requirements.txtcd example
  14. 14. Mumblr (starting Mongo)http://www.mongodb.org/display/DOCS/Quickstart+Unixcurl http://downloads.mongodb.org/linux...tgz > mongo.tgztar xzf mongo.tgzsudo chown `id -u` /data/dbsudo chown `id -u` /data/db/*./mongodb-linux-i686-2.0.2/bin/mongod./mongodb-linux-i686-2.0.2/bin/mongouse mumblr-exampledb.dropDatabase()
  15. 15. Mumblr (adding user)ls mumblr/management/commands/python manage.py addusepython manage.py runserver
  16. 16. Points • Django is an excellent framework for not too complicated sites • MongoDB is #1 NoSQL database - try it • Djangists may find Mongoengine convenient • Do reinvent the wheel • Make it easy for others to start using it
  17. 17. CreditsLogos • Django • Mongo • MongoengineComics • How to Write a CV • The Hard Life Of A NoSQL Coderrst2pdf • rst2pdf • style by Alexis Métaireau was partially used

×