MongoDB hearts Django? (Django NYC)
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

MongoDB hearts Django? (Django NYC)

  • 14,458 views
Uploaded on

A look at how to work with MongoDB and Django, and how we can make the interaction even better in the future.

A look at how to work with MongoDB and Django, and how we can make the interaction even better in the future.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
14,458
On Slideshare
14,204
From Embeds
254
Number of Embeds
4

Actions

Shares
Downloads
169
Comments
0
Likes
21

Embeds 254

http://www.slideshare.net 248
http://paper.li 4
http://translate.googleusercontent.com 1
http://127.0.0.1 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • blog post
    twitter

Transcript

  • 1. open-source, high-performance, schema-free, document-oriented database http://www.mongodb.org/
  • 2. The Web framework for perfectionists with deadlines http://www.djangoproject.com/
  • 3. “One size fits all” no longer RDBMS (Oracle, MySQL) Non-relational New gen. OLAP (vertica, aster, greenplum) operational stores (“NoSQL”)
  • 4. NoSQL really means: non-relational next generation operational datastores and databases
  • 5. Scaling out no joins + light transactional semantics = horizontally scalable architectures
  • 6. Data models no joins + light transactional semantics = horizontally scalable architectures important side effect : new data models = improved ways to develop applications
  • 7. Data models Key/value memcached, dynamo, voldemort Tabular bigtable, cassandra, hbase, hypertable Document-oriented couchdb,
  • 8. MongoDB in two minutes • Documents (think rows) are dicts: {“hello”: “world”} {“hello”: “world”, “foo”: [{“bar”: 1}]} • Collections (think tables) are schema-free • Queries are dynamic • Great single node performance • Built in replication and auto-sharding • No complex transactions
  • 9. ?
  • 10. Yes... ...but also sometimes no
  • 11. Similar to + • A lot of Django doesn’t depend on django.db: • URL dispatch, templates, I18N, caching, etc. • Some things do: • Models • Auth • Sessions • Admin
  • 12. settings.py DATABASE_ENGINE = '' DATABASE_NAME = '' DATABASE_USER = '' DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = '' MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', # 'django.contrib.sessions.middleware.SessionMiddleware', # 'django.contrib.auth.middleware.AuthenticationMiddleware', ) INSTALLED_APPS = ( # 'django.contrib.auth', 'django.contrib.contenttypes', # 'django.contrib.sessions', 'django.contrib.sites', )
  • 13. Representing a Poll {'question': 'Do MongoDB + Django <3 each other?', 'pub_date': datetime.datetime(2010, 1, 21), 'choices': [{'votes': 35, 'choice': 'Yes!'}, {'votes': 2, 'choice': 'No...'}]}
  • 14. models.py (PyMongo) def save_poll(question): return db.polls.insert({"question": question, "pub_date": datetime.utcnow()}) def all_polls(): return db.polls.find() def add_choice(poll_id, choice): db.polls.update({"_id": poll_id}, {"$push": {"choices": {"choice": choice, "votes": 0}}}) def add_vote(poll_id, choice): db.polls.update({"_id": poll_id}, {"$inc": {"choices.%d.votes" % choice: 1}}) http://api.mongodb.org/python
  • 15. models.py (MongoKit) class Poll(mongokit.Document): structure = {"question": str, "pub_date": datetime, "choices": [{"choice": str, "votes": int}]} required_fields = ["question"] default_values = {"pub_date": datetime.utcnow()} http://bytebucket.org/namlook/mongokit
  • 16. models.py (Ming) class Poll(ming.Document): class __mongometa__: session = session name = "polls" _id = ming.Field(ming.schema.ObjectId) question = ming.Field(str, required=True) pub_date = ming.Field(datetime.datetime, if_missing=datetime.datetime.utcnow) choices = ming.Field([{"choice": str, "votes": int}]) http://merciless.sourceforge.net/
  • 17. mango - sessions and auth • Full sessions support • mango provided User class • supports is_authenticated(), set_password(), etc. http://github.com/vpulim/mango
  • 18. mango - sessions and auth SESSION_ENGINE = 'mango.session' AUTHENTICATION_BACKENDS = ('mango.auth.Backend',) MONGODB_HOST = 'localhost' MONGODB_PORT = None MONGODB_NAME = 'mydb' http://github.com/vpulim/mango
  • 19. What about admin? • No great solution... yet. • Could replace admin app like mango does for sessions / auth • Or...
  • 20. Supporting MongoDB in django.db • Best solution (long term) • http://bitbucket.org/kpot/django-mongodb/ • http://bitbucket.org/wkornewald/django-nonrel/ • http://code.djangoproject.com/wiki/NonSqlBackends
  • 21. 1. Download MongoDB http://www.mongodb.org 2. Try it out! 3. (And help us make things work better with Django!)
  • 22. • http://www.mongodb.org • irc.freenode.net#mongodb • mongodb-user on google groups • @mongodb, @mdirolf • mike@10gen.com • http://www.slideshare.net/mdirolf • http://github.com/mdirolf/djanMon/