• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MongoDB hearts Django? (Django NYC)
 

MongoDB hearts Django? (Django NYC)

on

  • 13,929 views

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.

Statistics

Views

Total Views
13,929
Views on SlideShare
13,675
Embed Views
254

Actions

Likes
17
Downloads
162
Comments
0

4 Embeds 254

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

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • blog post <br /> twitter

MongoDB hearts Django? (Django NYC) MongoDB hearts Django? (Django NYC) Presentation Transcript

  • open-source, high-performance, schema-free, document-oriented database http://www.mongodb.org/
  • The Web framework for perfectionists with deadlines http://www.djangoproject.com/
  • “One size fits all” no longer RDBMS (Oracle, MySQL) Non-relational New gen. OLAP (vertica, aster, greenplum) operational stores (“NoSQL”)
  • NoSQL really means: non-relational next generation operational datastores and databases
  • Scaling out no joins + light transactional semantics = horizontally scalable architectures
  • Data models no joins + light transactional semantics = horizontally scalable architectures important side effect : new data models = improved ways to develop applications
  • Data models Key/value memcached, dynamo, voldemort Tabular bigtable, cassandra, hbase, hypertable Document-oriented couchdb,
  • 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
  • ?
  • Yes... ...but also sometimes no
  • 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
  • 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', )
  • 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...'}]}
  • 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
  • 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
  • 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/
  • mango - sessions and auth • Full sessions support • mango provided User class • supports is_authenticated(), set_password(), etc. http://github.com/vpulim/mango
  • 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
  • What about admin? • No great solution... yet. • Could replace admin app like mango does for sessions / auth • Or...
  • 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
  • 1. Download MongoDB http://www.mongodb.org 2. Try it out! 3. (And help us make things work better with Django!)
  • • 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/