SlideShare a Scribd company logo
open-source, high-performance,
schema-free, document-oriented
           database
RDBMS

• Great for many applications
• Shortcomings
 • Scalability
 • Flexibility
CAP Theorem

• Consistency
• Availability
• Tolerance to network Partitions
• Pick two

       http://www.cs.berkeley.edu/~brewer/cs262b-2004/PODC-keynote.pdf
ACID vs BASE

•   Atomicity
                  •   Basically Available
•   Consistency
                  •   Soft state
•   Isolation
                  •   Eventually consistent
•   Durability
Schema-free

• Loosening constraints - added flexibility
• Dynamically typed languages
• Migrations
• Focus on performance
• Rich dynamic queries
• Secondary indexes
• Replication / failover
• Auto-sharding
• Many platforms / languages supported
MongoDB NYC Python
Good at

• The web
• Caching
• High volume / low value
• Scalability
Less good at

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

• Python driver for MongoDB
• Pure Python, with optional C extension
• Installation (setuptools):
         easy_install pymongo
Document
• Unit of storage (think row)
• Just a dictionary
• Can store many Python types:
 • None, bool, int, float, string / unicode,
    dict, datetime.datetime, compiled re
• Some special types:
 • SON, Binary, ObjectId, DBRef
Collection

• Schema-free equivalent of a table
• Logical groups of documents
• Indexes are per-collection
_id

• Special key
• Present in all documents
• Unique across a Collection
• Any type you want
Blog back-end
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...”,
        “tags”: [“mongodb”, “python”]}

post_id = db.posts.save(post)
Embedding a comment

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

db.posts.update({“_id”: post_id},
                {“$push”: {“comments”: c}})
Last 10 posts

query = db.posts.find()
          .sort(“date”, DESCENDING)
          .limit(10)

for post in query:
    print post[“text”]
Posts by author


db.posts.find({“author”: “mike”})
Posts in the last week

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

db.posts.find({“date”: {“$gt”: last_week}})
Posts ending with
            ‘Python’


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




            ... and fast
db.posts.create_index(“tag”, ASCENDING)
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.utcnow(),
        “text”: “another blog post...”,
        “tags”: [“meetup”, “python”],
        “title”: “Document Oriented Dbs”}

post_id = db.posts.save(post)
Advanced queries

    • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin
    • where()
db.posts.find().where(“this.author == ‘mike’”)

    • group()
Other cool stuff

• Capped collections
• Unique indexes
• Mongo shell
• GridFS
• MongoKit (on pypi)
• Download MongoDB
  http://www.mongodb.org

• Install PyMongo
• Try it out!
• http://www.mongodb.org
• irc.freenode.net#mongodb
• mongodb-user on google groups
• @mongodb, @mdirolf
• mike@10gen.com
• http://www.slideshare.net/mdirolf
• Differences
 • MVCC based
 • Replication as path to scalability
 • Query through predefined views
 • ACID
 • REST

More Related Content

What's hot (20)

PPTX
Mongodb basics and architecture
Bishal Khanal
 
PDF
Introduction to MongoDB
Mike Dirolf
 
PPTX
Mongo db
Raghu nath
 
PPTX
MongoDB basics & Introduction
Jerwin Roy
 
PPTX
Mongodb introduction and_internal(simple)
Kai Zhao
 
PPTX
Basics of MongoDB
HabileLabs
 
PPTX
Top 10 frameworks of node js
HabileLabs
 
PPTX
Mongo db workshop # 01
FarhatParveen10
 
DOCX
Mongo db report
Hyphen Call
 
PPTX
Intro To Mongo Db
chriskite
 
PPTX
Mongodb @ vrt
JWORKS powered by Ordina
 
PPT
MongoDB Pros and Cons
johnrjenson
 
PPTX
Webinar: What's new in the .NET Driver
MongoDB
 
PPTX
The Basics of MongoDB
valuebound
 
PPTX
MongoDB 101
Abhijeet Vaikar
 
PPTX
Mongo DB 102
Abhijeet Vaikar
 
PPTX
MongoDB Schema Design by Examples
Hadi Ariawan
 
PDF
Mongo db dhruba
Dhrubaji Mandal ♛
 
KEY
Mongodb intro
christkv
 
Mongodb basics and architecture
Bishal Khanal
 
Introduction to MongoDB
Mike Dirolf
 
Mongo db
Raghu nath
 
MongoDB basics & Introduction
Jerwin Roy
 
Mongodb introduction and_internal(simple)
Kai Zhao
 
Basics of MongoDB
HabileLabs
 
Top 10 frameworks of node js
HabileLabs
 
Mongo db workshop # 01
FarhatParveen10
 
Mongo db report
Hyphen Call
 
Intro To Mongo Db
chriskite
 
MongoDB Pros and Cons
johnrjenson
 
Webinar: What's new in the .NET Driver
MongoDB
 
The Basics of MongoDB
valuebound
 
MongoDB 101
Abhijeet Vaikar
 
Mongo DB 102
Abhijeet Vaikar
 
MongoDB Schema Design by Examples
Hadi Ariawan
 
Mongo db dhruba
Dhrubaji Mandal ♛
 
Mongodb intro
christkv
 

Similar to MongoDB NYC Python (20)

KEY
MongoDB EuroPython 2009
Mike Dirolf
 
KEY
MongoDB at ZPUGDC
Mike Dirolf
 
KEY
MongoDB London PHP
Mike Dirolf
 
KEY
MongoDB at RuPy
Mike Dirolf
 
KEY
MongoDB Strange Loop 2009
Mike Dirolf
 
KEY
MongoDB SF Python
Mike Dirolf
 
KEY
MongoDB at CodeMash 2.0.1.0
Mike Dirolf
 
PDF
MongoDB Basics
Sarang Shravagi
 
PPT
9. Document Oriented Databases
Fabio Fumarola
 
PDF
MongoDB.pdf
KuldeepKumar778733
 
PDF
MongoDB: a gentle, friendly overview
Antonio Pintus
 
PDF
MongoDB at FrozenRails
Mike Dirolf
 
PDF
Mongo db japan
rogerbodamer
 
KEY
MongoDB SF Ruby
Mike Dirolf
 
PDF
Mongodb my
Alexey Gaziev
 
PDF
MongoDB
SPBRUBY
 
ODP
Python and MongoDB
Christiano Anderson
 
PDF
Mongo db eveningschemadesign
MongoDB APAC
 
KEY
MongoDB at RubyEnRails 2009
Mike Dirolf
 
MongoDB EuroPython 2009
Mike Dirolf
 
MongoDB at ZPUGDC
Mike Dirolf
 
MongoDB London PHP
Mike Dirolf
 
MongoDB at RuPy
Mike Dirolf
 
MongoDB Strange Loop 2009
Mike Dirolf
 
MongoDB SF Python
Mike Dirolf
 
MongoDB at CodeMash 2.0.1.0
Mike Dirolf
 
MongoDB Basics
Sarang Shravagi
 
9. Document Oriented Databases
Fabio Fumarola
 
MongoDB.pdf
KuldeepKumar778733
 
MongoDB: a gentle, friendly overview
Antonio Pintus
 
MongoDB at FrozenRails
Mike Dirolf
 
Mongo db japan
rogerbodamer
 
MongoDB SF Ruby
Mike Dirolf
 
Mongodb my
Alexey Gaziev
 
MongoDB
SPBRUBY
 
Python and MongoDB
Christiano Anderson
 
Mongo db eveningschemadesign
MongoDB APAC
 
MongoDB at RubyEnRails 2009
Mike Dirolf
 
Ad

More from Mike Dirolf (9)

PDF
Indexing
Mike Dirolf
 
PDF
Inside MongoDB: the Internals of an Open-Source Database
Mike Dirolf
 
KEY
Inside PyMongo - MongoNYC
Mike Dirolf
 
PDF
FrozenRails Training
Mike Dirolf
 
KEY
Python Development (MongoSF)
Mike Dirolf
 
KEY
MongoDB: How it Works
Mike Dirolf
 
KEY
MongoDB hearts Django? (Django NYC)
Mike Dirolf
 
PDF
MongoDB at RubyConf
Mike Dirolf
 
KEY
MongoDB Hadoop DC
Mike Dirolf
 
Indexing
Mike Dirolf
 
Inside MongoDB: the Internals of an Open-Source Database
Mike Dirolf
 
Inside PyMongo - MongoNYC
Mike Dirolf
 
FrozenRails Training
Mike Dirolf
 
Python Development (MongoSF)
Mike Dirolf
 
MongoDB: How it Works
Mike Dirolf
 
MongoDB hearts Django? (Django NYC)
Mike Dirolf
 
MongoDB at RubyConf
Mike Dirolf
 
MongoDB Hadoop DC
Mike Dirolf
 
Ad

Recently uploaded (20)

PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Essential Content-centric Plugins for your Website
Laura Byrne
 
PDF
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Home Cleaning App Development Services.pdf
V3cube
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Essential Content-centric Plugins for your Website
Laura Byrne
 
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Home Cleaning App Development Services.pdf
V3cube
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 

MongoDB NYC Python