open-source, high-performance,
schema-free, document-oriented
           database



                       http://www.mon...
“One size fits all”
   no longer
                               RDBMS
                          (Oracle, MySQL)




       ...
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...
Documents and BSON

          {“hello”: “world”}


{“hello”: “world”, “foo”: [{“bar”: 1}]}
Schema-free collections


• Dynamically typed languages
• Migrations
• Still define indexes per collection
Dynamic queries

• Administration
• Ease of development / familiarity
Atomic update modifiers
Focus on performance
Replication
                                            Replica sets
        Master - slave

                             ...
Auto-sharding
                    Shards

           mongod   mongod    mongod
                                         .....
Many supported
languages and platforms
Good at

• The web
• Caching
• High volume data
• Scalability
Less good at

• Highly transactional
• Ad-hoc business intelligence
• Problems that require SQL
_id

• Special key
• Present in all documents
• Unique across a Collection
• Any type you want
Post

{“author”: “mike”,
 “date”: datetime.datetime.utcnow(),
 “text”: “my blog post...”,
 “tags”: [“mongodb”, “python”]}
Comment


{“author”: “eliot”,
 “date”: datetime.datetime.utcnow(),
 “text”: “great post!”}
New post

post = {“author”: “mike”,
        “date”: datetime.datetime.utcnow(),
        “text”: “my blog post...”,
       ...
Embedding a comment

c = {“author”: “eliot”,
     “date”: datetime.datetime.utcnow(),
     “text”: “great post!”}

db.post...
Posts by author


db.posts.find({“author”: “mike”})
Last 10 posts


db.posts.find()
        .sort(“date”, DESCENDING)
        .limit(10)
Posts in the last week

last_week = datetime.datetime.utcnow() +
            datetime.timedelta(days=-7)

db.posts.find({“...
Posts ending with
            ‘Python’


db.posts.find({“text”: re.compile(“Python$”)})
Posts with a tag
db.posts.find({“tags”: “mongodb”})




          ... and fast
db.posts.create_index(“tags”)
Counting posts


db.posts.count()

db.posts.find({“author”: “mike”}).count()
Basic paging

page = 2
page_size = 15

db.posts.find().limit(page_size)
               .skip(page * page_size)
Migration: adding titles
  • Easy - just start adding them:
post = {“author”: “mike”,
        “date”: datetime.datetime.ut...
Advanced queries

    • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin
    • where()
db.posts.find().where(“this.author == ‘mi...
Other cool stuff

• Aggregation and map reduce
• Capped collections
• Unique indexes
• Mongo shell
• GridFS
?
Yes...
 ...but also sometimes no
Similar to                            +
• A lot of Django doesn’t depend on django.db:
 • URL dispatch, templates, I18N, c...
settings.py
DATABASE_ENGINE = ''
DATABASE_NAME = ''
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_...
Representing a Poll

{'question': 'Do MongoDB + Django <3 each other?',
 'pub_date': datetime.datetime(2010, 1, 21),
 'cho...
models.py (PyMongo)
def save_poll(question):
  return db.polls.insert({"question": question,
                  "pub_date":...
models.py (MongoKit)

class Poll(mongokit.Document):
   structure = {"question": str,
            "pub_date": datetime,
  ...
models.py (Ming)
class Poll(ming.Document):

  class __mongometa__:
     session = session
     name = "polls"

  _id = mi...
mango - sessions and auth


•   Full sessions support
•   mango provided User class
    •   supports is_authenticated(), s...
mango - sessions and auth


SESSION_ENGINE = 'mango.session'
AUTHENTICATION_BACKENDS = ('mango.auth.Backend',)
MONGODB_HOS...
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/

•   ...
1. Download MongoDB
   http://www.mongodb.org

2. Try it out!

3. Let us know what you think.
NoSQL Live from Boston

Thursday, March 11

http://www.10gen.com/events
• http://api.mongodb.org/python
• http://www.mongodb.org
• irc.freenode.net#mongodb
• mongodb-user on google groups
• @mon...
MongoDB at ZPUGDC
Upcoming SlideShare
Loading in...5
×

MongoDB at ZPUGDC

5,237

Published on

Talk about MongoDB, PyMongo and integrating MongoDB w/ Django from the DC Python Meetup group.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,237
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
118
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • blog post
    twitter
  • MongoDB at ZPUGDC

    1. 1. open-source, high-performance, schema-free, document-oriented database http://www.mongodb.org/
    2. 2. “One size fits all” no longer RDBMS (Oracle, MySQL) Non-relational New gen. OLAP (vertica, aster, greenplum) operational stores (“NoSQL”)
    3. 3. NoSQL really means: non-relational next generation operational datastores and databases
    4. 4. Scaling out no joins + light transactional semantics = horizontally scalable architectures
    5. 5. Data models no joins + light transactional semantics = horizontally scalable architectures important side effect : new data models = improved ways to develop applications
    6. 6. Documents and BSON {“hello”: “world”} {“hello”: “world”, “foo”: [{“bar”: 1}]}
    7. 7. Schema-free collections • Dynamically typed languages • Migrations • Still define indexes per collection
    8. 8. Dynamic queries • Administration • Ease of development / familiarity
    9. 9. Atomic update modifiers
    10. 10. Focus on performance
    11. 11. Replication Replica sets Master - slave master slave master master slave slave slave slave master master slave slave master
    12. 12. Auto-sharding Shards mongod mongod mongod ... Config mongod mongod mongod Servers mongod mongod mongod mongos mongos ... client
    13. 13. Many supported languages and platforms
    14. 14. Good at • The web • Caching • High volume data • Scalability
    15. 15. Less good at • Highly transactional • Ad-hoc business intelligence • Problems that require SQL
    16. 16. _id • Special key • Present in all documents • Unique across a Collection • Any type you want
    17. 17. Post {“author”: “mike”, “date”: datetime.datetime.utcnow(), “text”: “my blog post...”, “tags”: [“mongodb”, “python”]}
    18. 18. Comment {“author”: “eliot”, “date”: datetime.datetime.utcnow(), “text”: “great post!”}
    19. 19. New post post = {“author”: “mike”, “date”: datetime.datetime.utcnow(), “text”: “my blog post...”, “tags”: [“mongodb”, “python”]} post_id = db.posts.save(post)
    20. 20. Embedding a comment c = {“author”: “eliot”, “date”: datetime.datetime.utcnow(), “text”: “great post!”} db.posts.update({“_id”: post_id}, {“$push”: {“comments”: c}})
    21. 21. Posts by author db.posts.find({“author”: “mike”})
    22. 22. Last 10 posts db.posts.find() .sort(“date”, DESCENDING) .limit(10)
    23. 23. Posts in the last week last_week = datetime.datetime.utcnow() + datetime.timedelta(days=-7) db.posts.find({“date”: {“$gt”: last_week}})
    24. 24. Posts ending with ‘Python’ db.posts.find({“text”: re.compile(“Python$”)})
    25. 25. Posts with a tag db.posts.find({“tags”: “mongodb”}) ... and fast db.posts.create_index(“tags”)
    26. 26. Counting posts db.posts.count() db.posts.find({“author”: “mike”}).count()
    27. 27. Basic paging page = 2 page_size = 15 db.posts.find().limit(page_size) .skip(page * page_size)
    28. 28. Migration: adding titles • Easy - just start adding them: post = {“author”: “mike”, “date”: datetime.datetime.utcnow(), “text”: “another blog post...”, “tags”: [“meetup”, “python”], “title”: “MongoDB @ DC Python”} post_id = db.posts.save(post)
    29. 29. Advanced queries • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin • where() db.posts.find().where(“this.author == ‘mike’ || this.title == ‘hello’”) • group()
    30. 30. Other cool stuff • Aggregation and map reduce • Capped collections • Unique indexes • Mongo shell • GridFS
    31. 31. ?
    32. 32. Yes... ...but also sometimes no
    33. 33. 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
    34. 34. 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', )
    35. 35. 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...'}]}
    36. 36. 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
    37. 37. 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
    38. 38. 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/
    39. 39. mango - sessions and auth • Full sessions support • mango provided User class • supports is_authenticated(), set_password(), etc. http://github.com/vpulim/mango
    40. 40. 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
    41. 41. What about admin? • No great solution... yet. • Could replace admin app like mango does for sessions / auth • Or...
    42. 42. 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
    43. 43. 1. Download MongoDB http://www.mongodb.org 2. Try it out! 3. Let us know what you think.
    44. 44. NoSQL Live from Boston Thursday, March 11 http://www.10gen.com/events
    45. 45. • http://api.mongodb.org/python • http://www.mongodb.org • irc.freenode.net#mongodb • mongodb-user on google groups • @mongodb, @mdirolf • mike@10gen.com
    1. A particular slide catching your eye?

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

    ×