SlideShare a Scribd company logo
Rick Copeland @rick446
Arborian Consulting, LLC
http://www.flickr.com/photos/fazen/9079179/
-   Get started with PyMongo


-   Sprinkle in some Ming schemas


-   ODM: When a dict just won’t do
>>>importpymongo
>>>conn = pymongo.Connection()
>>>conn
Connection('localhost', 27017)
>>>conn.test
Database(Connection('localhost', 27017), u'test')
>>>conn.test.foo
Collection(Database(Connection('localhost', 27017), u'test'), u'foo')
>>>conn['test-db']
Database(Connection('localhost', 27017), u'test-db')
>>>conn['test-db']['foo-collection']
Collection(Database(Connection('localhost', 27017), u'test-db'), u'foo-
  collection')
>>>conn.test.foo.bar.baz
Collection(Database(Connection('localhost', 27017), u'test'), u'foo.bar.baz')
>>>db = conn.test
>>>id = db.foo.insert({'bar':1, 'baz':[ 1, 2, {'k':5} ] })
>>>id
ObjectId('4e712e21eb033009fa000000')                          Auto-Generated _id
>>>db.foo.find()
<pymongo.cursor.Cursor object at 0x29c7d50>
>>>list(db.foo.find())                                             Cursors are python
[{u'bar': 1, u'_id': ObjectId('4e712e21eb033009fa000000'), u'baz': [1, 2, {'k': 5}]}]
                                                                       generators
>>>db.foo.update({'_id':id}, {'$set': { 'bar':2}})
>>>db.foo.find().next()
{u'bar': 2, u'_id': ObjectId('4e712e21eb033009fa000000'), u'baz': [1, 2, {'k': 5}]}
>>>db.foo.remove({'_id':id})
>>>list(db.foo.find())
[]
                                                             Remove uses same
                                                           query language as find()
>>>db.foo.insert([ dict(x=x) forxinrange(10) ])
[ObjectId('4e71313aeb033009fa00000b'), … ]
>>>list(db.foo.find({ 'x': {'$gt': 3} }))                                    Range Query
[{u'x': 4, u'_id': ObjectId('4e71313aeb033009fa00000f')}, {u'x': 5, u'_id':
     ObjectId('4e71313aeb033009fa000010')}, {u'x': 6, u'_id':
     ObjectId('4e71313aeb033009fa000011')}, …]
>>>list(db.foo.find({ 'x': {'$gt': 3} }, { '_id':0 } ))
[{u'x': 4}, {u'x': 5}, {u'x': 6}, {u'x': 7}, {u'x': 8}, {u'x': 9}]
>>>list(db.foo.find({ 'x': {'$gt': 3} }, { '_id':0 } )
....skip(1).limit(2))
[{u'x': 5}, {u'x': 6}]
>>>db.foo.ensure_index([
                                                                   Partial Retrieval
...('x’,pymongo.ASCENDING),('y’,pymongo.DESCENDING)])
u'x_1_y_-1’


                                                      Compound Indexes
One Rule (for now): Avoid Javascript

                                       http://www.flickr.com/photos/lizjones/295567490/
   You gotta write Javascript (for now)

   It’s pretty slow (single-threaded JS engine) 
                                                    MongoDB 2.2 with New
   Javascript is used by                           Aggregation Framework
     $where in a query                            Coming Real Soon Now ™
     .group(key, condition, initial, reduce, finalize=None)
     .map_reduce(map, reduce, out, finalize=None, …)


   Sharding gives some parallelism with .map_reduce() (and
    possibly ‘$where’). Otherwise you’re single threaded.
>>>importgridfs
>>>fs = gridfs.GridFS(db)                           Python context
>>>withfs.new_file() asfp:                             manager
... fp.write('The file')
...
>>>fp
<gridfs.grid_file.GridIn object at 0x2cae910>
>>>fp._id
ObjectId('4e727f64eb03300c0b000003')            Retrieve file by _id
>>>fs.get(fp._id).read()
'The file'

     Arbitrary data can be stored in the ‘fp’ object – it’s
      just a Document (but please put it in ‘fp.metadata’)
         Mime type, links to other docs, etc.
>>>file_id = fs.put('Moar data!', filename='foo.txt')
>>>fs.get_last_version('foo.txt').read()
'Moar data!’
                                                                         Create file by
                                                                           filename
>>>file_id = fs.put('Evenmoar data!', filename='foo.txt')
>>>fs.get_last_version('foo.txt').read()
'Even moar data!’
>>>fs.get_version('foo.txt', -2).read()
'Moar data!’
>>>fs.list()
                                                            “2nd from the last”
[u'foo.txt']
>>>fs.delete(fs.get_last_version('foo.txt')._id)
>>>fs.list()
[u'foo.txt']
>>>fs.delete(fs.get_last_version('foo.txt')._id)
>>>fs.list()
[]
-   Get started with PyMongo


-   Sprinkle in some Ming schemas


-   ODM: When a dict just won’t do
   Your data has a schema
       Your database can define and enforce it
       It can live in your application (as with MongoDB)
       Nice to have the schema defined in one place in the code


   Sometimes you need a “migration”
       Changing the structure/meaning of fields
       Adding indexes, particularly unique indexes
       Sometimes lazy, sometimes eager


   “Unit of work:” Queuing up all your updates can be handy
Model              Datastore
(schema)             (database)



           Session
>>>importming.datastore
>>>ds = ming.datastore.DataStore('mongodb://localhost:27017', database='test')
>>>ds.db                                                         Connection +
Database(Connection('localhost', 27017), u'test')                 Database
>>>session = ming.Session(ds)
>>>session.db
Database(Connection('localhost', 27017), u'test')
>>>ming.configure(**{                                          Optimized for config
... 'ming.main.master':'mongodb://localhost:27017',                   files
... 'ming.main.database':'test'})
>>>Session.by_name('main').db
Database(Connection(u'localhost', 27017), u'test')
http://www.flickr.com/photos/pictureclara/5333266789/
frommingimport schema, Field

WikiDoc= collection(‘wiki_page', session,
Field('_id', schema.ObjectId()),
                                                     Index created on
Field('title', str, index=True),
                                                         import
Field('text', str))

CommentDoc= collection(‘comment', session,
Field('_id', schema.ObjectId()),
Field('page_id', schema.ObjectId(), index=True),
Field('text', str))
                                                   Shorthand for
                                                   schema.String
frommingimport Document, Session, Field

classWikiDoc(Document):
class__mongometa__:
session=Session.by_name(’main')
name='wiki_page’
indexes=[ ('title') ]
title = Field(str)
text = Field(str)


   Old declarative syntax continues to exist and be
    supported, but it’s not being actively improved
   Sometimes nice when you want additional
    methods/attrs on your document class
>>>doc = WikiDoc(dict(title='Cats', text='I can hazcheezburger?'))
>>>doc.m.save()
>>>WikiDoc.m.find()
<ming.base.Cursor object at 0x2c2cd90>
>>>WikiDoc.m.find().all()                                       Documents are dict
                                                                     subclasses
[{'text': u'I can hazcheezburger?', '_id': ObjectId('4e727163eb03300c0b000001'),
     'title': u'Cats'}]
>>>WikiDoc.m.find().one().text
u'Ican hazcheezburger?’
>>>doc = WikiDoc(dict(tietul='LOL', text='Invisible bicycle'))
>>>doc.m.save()
Traceback(most recent call last):
File "<stdin>", line 1,
  …                                                        Exception pinpoints
ming.schema.Invalid: <class 'ming.metadata.Document<wiki_page>'>:
                                                                problem
Extra keys: set(['tietul'])
>>>ming.datastore.DataStore('mim://', database='test').db
mim.Database(test)



   MongoDB is (generally) fast
       … except when creating databases
       … particularly when you preallocate


   Unit tests like things to be isolated


   MIM gives you isolation at the expense of speed & scaling
-   Get started with PyMongo


-   Sprinkle in some Ming schemas


-   ODM: When a dict just won’t do
frommingimport schema, Field
fromming.odmimport (mapper, Mapper, RelationProperty,
ForeignIdProperty)
                                                          Plain Old Python
WikiDoc= collection('wiki_page',session, … )                   Classes
CommentDoc= collection(’comment’, session, … )

classWikiPage(object): pass                               Map classes to
classComment(object): pass                              collection + session
odmsession.mapper(WikiPage, WikiDoc, properties=dict(
comments=RelationProperty('WikiComment')))
odmsession.mapper(Comment, CommentDoc, properties=dict(
page_id=ForeignIdProperty('WikiPage'),
page=RelationProperty('WikiPage')))

                                                               “Relations”
classWikiPage(MappedClass):
class__mongometa__:
session = main_odm_session
name='wiki_page’
indexes = [ 'title']

    _id = FieldProperty(S.ObjectId)
title = FieldProperty(str)
text = FieldProperty(str)
comments = RelationProperty(’Comment’)
       Session ODMSession
       My_collection.m… My_mapped_class.query…
       ODMSessionactually does stuff
           Track object identity
           Track object modifications
           Unit of work flushing all changes at once
    >>>pg = WikiPage(title='MyPage', text='is here')
    >>>session.db.wiki_page.count()
    0
    >>>main_orm_session.flush()
    >>>session.db.wiki_page.count()
    1
http://www.flickr.com/photos/39747297@N05/5229733647/
   Various plug points in the session
       before_flush
       after_flush


   Some uses
       Logging changes to sensitive data or for analytics
       Full-text search indexing
       “last modified” fields
       Performance instrumentation
   Various plug points in the mapper
       before_/after_:
           Insert
           Update
           Delete
           Remove


   Some uses
       Collection/model-specific logging (user creation, etc.)
       Anything you might want a SessionExtension for but
        would rather do per-model
PyMongo
http://api.mongodb.org/python
Apache License



Ming
http://sf.net/projects/merciless/
MIT License
Rick Copeland @rick446
   Arborian Consulting, LLC




Feedback? http://www.surveymonkey.com/s/5DLCYKN

                              http://www.flickr.com/photos/f-oxymoron/5005673112/
Ad

More Related Content

What's hot (20)

Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
Skills Matter
 
The Ring programming language version 1.8 book - Part 34 of 202
The Ring programming language version 1.8 book - Part 34 of 202The Ring programming language version 1.8 book - Part 34 of 202
The Ring programming language version 1.8 book - Part 34 of 202
Mahmoud Samir Fayed
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
Christian Baranowski
 
Drupal 8 database api
Drupal 8 database apiDrupal 8 database api
Drupal 8 database api
Viswanath Polaki
 
The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196
Mahmoud Samir Fayed
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
Mahmoud Samir Fayed
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
MongoDB
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
Takahiro Inoue
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 31 of 189
The Ring programming language version 1.6 book - Part 31 of 189The Ring programming language version 1.6 book - Part 31 of 189
The Ring programming language version 1.6 book - Part 31 of 189
Mahmoud Samir Fayed
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemy
Jaime Buelta
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
MongoDB
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
Mahmoud Samir Fayed
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
MongoDB
 
The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180
Mahmoud Samir Fayed
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
Eishay Smith
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
Gabriele Lana
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
Skills Matter
 
The Ring programming language version 1.8 book - Part 34 of 202
The Ring programming language version 1.8 book - Part 34 of 202The Ring programming language version 1.8 book - Part 34 of 202
The Ring programming language version 1.8 book - Part 34 of 202
Mahmoud Samir Fayed
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
Christian Baranowski
 
The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196
Mahmoud Samir Fayed
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
Mahmoud Samir Fayed
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
MongoDB
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
Takahiro Inoue
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 31 of 189
The Ring programming language version 1.6 book - Part 31 of 189The Ring programming language version 1.6 book - Part 31 of 189
The Ring programming language version 1.6 book - Part 31 of 189
Mahmoud Samir Fayed
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemy
Jaime Buelta
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
MongoDB
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
Mahmoud Samir Fayed
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
MongoDB
 
The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180The Ring programming language version 1.5.1 book - Part 27 of 180
The Ring programming language version 1.5.1 book - Part 27 of 180
Mahmoud Samir Fayed
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
Eishay Smith
 

Similar to Rapid and Scalable Development with MongoDB, PyMongo, and Ming (20)

Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
MongoDB
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
Mike Dirolf
 
Latinoware
LatinowareLatinoware
Latinoware
kchodorow
 
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
MongoSF
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
Boris Nadion
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
Colin Su
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
용 최
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
Functional Thursday
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
John David Duncan
 
PyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorialPyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorial
jbellis
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
Eric ShangKuan
 
Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17
Michele Orselli
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]
Devon Bernard
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
Henry Schreiner
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDB
DoThinger
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
MongoDB
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
Mike Dirolf
 
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
MongoSF
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
Boris Nadion
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
Colin Su
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
용 최
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
Functional Thursday
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
John David Duncan
 
PyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorialPyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorial
jbellis
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
Eric ShangKuan
 
Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17
Michele Orselli
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]
Devon Bernard
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
Henry Schreiner
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDB
DoThinger
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
Ad

More from Rick Copeland (12)

Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Schema Design at Scale
Schema Design at ScaleSchema Design at Scale
Schema Design at Scale
Rick Copeland
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
Rick Copeland
 
Chef on MongoDB and Pyramid
Chef on MongoDB and PyramidChef on MongoDB and Pyramid
Chef on MongoDB and Pyramid
Rick Copeland
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
Rick Copeland
 
Chef on Python and MongoDB
Chef on Python and MongoDBChef on Python and MongoDB
Chef on Python and MongoDB
Rick Copeland
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
Rick Copeland
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Rick Copeland
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rick Copeland
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Rick Copeland
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDB
Rick Copeland
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Schema Design at Scale
Schema Design at ScaleSchema Design at Scale
Schema Design at Scale
Rick Copeland
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
Rick Copeland
 
Chef on MongoDB and Pyramid
Chef on MongoDB and PyramidChef on MongoDB and Pyramid
Chef on MongoDB and Pyramid
Rick Copeland
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
Rick Copeland
 
Chef on Python and MongoDB
Chef on Python and MongoDBChef on Python and MongoDB
Chef on Python and MongoDB
Rick Copeland
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
Rick Copeland
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Rick Copeland
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rick Copeland
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Rick Copeland
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDB
Rick Copeland
 
Ad

Recently uploaded (20)

Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 

Rapid and Scalable Development with MongoDB, PyMongo, and Ming

  • 3. - Get started with PyMongo - Sprinkle in some Ming schemas - ODM: When a dict just won’t do
  • 4. >>>importpymongo >>>conn = pymongo.Connection() >>>conn Connection('localhost', 27017) >>>conn.test Database(Connection('localhost', 27017), u'test') >>>conn.test.foo Collection(Database(Connection('localhost', 27017), u'test'), u'foo') >>>conn['test-db'] Database(Connection('localhost', 27017), u'test-db') >>>conn['test-db']['foo-collection'] Collection(Database(Connection('localhost', 27017), u'test-db'), u'foo- collection') >>>conn.test.foo.bar.baz Collection(Database(Connection('localhost', 27017), u'test'), u'foo.bar.baz')
  • 5. >>>db = conn.test >>>id = db.foo.insert({'bar':1, 'baz':[ 1, 2, {'k':5} ] }) >>>id ObjectId('4e712e21eb033009fa000000') Auto-Generated _id >>>db.foo.find() <pymongo.cursor.Cursor object at 0x29c7d50> >>>list(db.foo.find()) Cursors are python [{u'bar': 1, u'_id': ObjectId('4e712e21eb033009fa000000'), u'baz': [1, 2, {'k': 5}]}] generators >>>db.foo.update({'_id':id}, {'$set': { 'bar':2}}) >>>db.foo.find().next() {u'bar': 2, u'_id': ObjectId('4e712e21eb033009fa000000'), u'baz': [1, 2, {'k': 5}]} >>>db.foo.remove({'_id':id}) >>>list(db.foo.find()) [] Remove uses same query language as find()
  • 6. >>>db.foo.insert([ dict(x=x) forxinrange(10) ]) [ObjectId('4e71313aeb033009fa00000b'), … ] >>>list(db.foo.find({ 'x': {'$gt': 3} })) Range Query [{u'x': 4, u'_id': ObjectId('4e71313aeb033009fa00000f')}, {u'x': 5, u'_id': ObjectId('4e71313aeb033009fa000010')}, {u'x': 6, u'_id': ObjectId('4e71313aeb033009fa000011')}, …] >>>list(db.foo.find({ 'x': {'$gt': 3} }, { '_id':0 } )) [{u'x': 4}, {u'x': 5}, {u'x': 6}, {u'x': 7}, {u'x': 8}, {u'x': 9}] >>>list(db.foo.find({ 'x': {'$gt': 3} }, { '_id':0 } ) ....skip(1).limit(2)) [{u'x': 5}, {u'x': 6}] >>>db.foo.ensure_index([ Partial Retrieval ...('x’,pymongo.ASCENDING),('y’,pymongo.DESCENDING)]) u'x_1_y_-1’ Compound Indexes
  • 7. One Rule (for now): Avoid Javascript http://www.flickr.com/photos/lizjones/295567490/
  • 8. You gotta write Javascript (for now)  It’s pretty slow (single-threaded JS engine)  MongoDB 2.2 with New  Javascript is used by Aggregation Framework  $where in a query Coming Real Soon Now ™  .group(key, condition, initial, reduce, finalize=None)  .map_reduce(map, reduce, out, finalize=None, …)  Sharding gives some parallelism with .map_reduce() (and possibly ‘$where’). Otherwise you’re single threaded.
  • 9. >>>importgridfs >>>fs = gridfs.GridFS(db) Python context >>>withfs.new_file() asfp: manager ... fp.write('The file') ... >>>fp <gridfs.grid_file.GridIn object at 0x2cae910> >>>fp._id ObjectId('4e727f64eb03300c0b000003') Retrieve file by _id >>>fs.get(fp._id).read() 'The file'  Arbitrary data can be stored in the ‘fp’ object – it’s just a Document (but please put it in ‘fp.metadata’)  Mime type, links to other docs, etc.
  • 10. >>>file_id = fs.put('Moar data!', filename='foo.txt') >>>fs.get_last_version('foo.txt').read() 'Moar data!’ Create file by filename >>>file_id = fs.put('Evenmoar data!', filename='foo.txt') >>>fs.get_last_version('foo.txt').read() 'Even moar data!’ >>>fs.get_version('foo.txt', -2).read() 'Moar data!’ >>>fs.list() “2nd from the last” [u'foo.txt'] >>>fs.delete(fs.get_last_version('foo.txt')._id) >>>fs.list() [u'foo.txt'] >>>fs.delete(fs.get_last_version('foo.txt')._id) >>>fs.list() []
  • 11. - Get started with PyMongo - Sprinkle in some Ming schemas - ODM: When a dict just won’t do
  • 12. Your data has a schema  Your database can define and enforce it  It can live in your application (as with MongoDB)  Nice to have the schema defined in one place in the code  Sometimes you need a “migration”  Changing the structure/meaning of fields  Adding indexes, particularly unique indexes  Sometimes lazy, sometimes eager  “Unit of work:” Queuing up all your updates can be handy
  • 13. Model Datastore (schema) (database) Session
  • 14. >>>importming.datastore >>>ds = ming.datastore.DataStore('mongodb://localhost:27017', database='test') >>>ds.db Connection + Database(Connection('localhost', 27017), u'test') Database >>>session = ming.Session(ds) >>>session.db Database(Connection('localhost', 27017), u'test') >>>ming.configure(**{ Optimized for config ... 'ming.main.master':'mongodb://localhost:27017', files ... 'ming.main.database':'test'}) >>>Session.by_name('main').db Database(Connection(u'localhost', 27017), u'test')
  • 16. frommingimport schema, Field WikiDoc= collection(‘wiki_page', session, Field('_id', schema.ObjectId()), Index created on Field('title', str, index=True), import Field('text', str)) CommentDoc= collection(‘comment', session, Field('_id', schema.ObjectId()), Field('page_id', schema.ObjectId(), index=True), Field('text', str)) Shorthand for schema.String
  • 17. frommingimport Document, Session, Field classWikiDoc(Document): class__mongometa__: session=Session.by_name(’main') name='wiki_page’ indexes=[ ('title') ] title = Field(str) text = Field(str)  Old declarative syntax continues to exist and be supported, but it’s not being actively improved  Sometimes nice when you want additional methods/attrs on your document class
  • 18. >>>doc = WikiDoc(dict(title='Cats', text='I can hazcheezburger?')) >>>doc.m.save() >>>WikiDoc.m.find() <ming.base.Cursor object at 0x2c2cd90> >>>WikiDoc.m.find().all() Documents are dict subclasses [{'text': u'I can hazcheezburger?', '_id': ObjectId('4e727163eb03300c0b000001'), 'title': u'Cats'}] >>>WikiDoc.m.find().one().text u'Ican hazcheezburger?’ >>>doc = WikiDoc(dict(tietul='LOL', text='Invisible bicycle')) >>>doc.m.save() Traceback(most recent call last): File "<stdin>", line 1, … Exception pinpoints ming.schema.Invalid: <class 'ming.metadata.Document<wiki_page>'>: problem Extra keys: set(['tietul'])
  • 19. >>>ming.datastore.DataStore('mim://', database='test').db mim.Database(test)  MongoDB is (generally) fast  … except when creating databases  … particularly when you preallocate  Unit tests like things to be isolated  MIM gives you isolation at the expense of speed & scaling
  • 20. - Get started with PyMongo - Sprinkle in some Ming schemas - ODM: When a dict just won’t do
  • 21. frommingimport schema, Field fromming.odmimport (mapper, Mapper, RelationProperty, ForeignIdProperty) Plain Old Python WikiDoc= collection('wiki_page',session, … ) Classes CommentDoc= collection(’comment’, session, … ) classWikiPage(object): pass Map classes to classComment(object): pass collection + session odmsession.mapper(WikiPage, WikiDoc, properties=dict( comments=RelationProperty('WikiComment'))) odmsession.mapper(Comment, CommentDoc, properties=dict( page_id=ForeignIdProperty('WikiPage'), page=RelationProperty('WikiPage'))) “Relations”
  • 22. classWikiPage(MappedClass): class__mongometa__: session = main_odm_session name='wiki_page’ indexes = [ 'title'] _id = FieldProperty(S.ObjectId) title = FieldProperty(str) text = FieldProperty(str) comments = RelationProperty(’Comment’)
  • 23. Session ODMSession  My_collection.m… My_mapped_class.query…  ODMSessionactually does stuff  Track object identity  Track object modifications  Unit of work flushing all changes at once >>>pg = WikiPage(title='MyPage', text='is here') >>>session.db.wiki_page.count() 0 >>>main_orm_session.flush() >>>session.db.wiki_page.count() 1
  • 25. Various plug points in the session  before_flush  after_flush  Some uses  Logging changes to sensitive data or for analytics  Full-text search indexing  “last modified” fields  Performance instrumentation
  • 26. Various plug points in the mapper  before_/after_:  Insert  Update  Delete  Remove  Some uses  Collection/model-specific logging (user creation, etc.)  Anything you might want a SessionExtension for but would rather do per-model
  • 28. Rick Copeland @rick446 Arborian Consulting, LLC Feedback? http://www.surveymonkey.com/s/5DLCYKN http://www.flickr.com/photos/f-oxymoron/5005673112/

Editor's Notes

  • #3: Who’s using mongodb? In production?Who’s using python? In production?Who’s using both together? In Production?I’m a consultant, but I *was* an engineer at SourceForgeI’ve been using MongoDB at SourceForge since 0.8, Python since 2002 or so, love them bothWe extracted our MongoDB libraries into a separate OSS project ‘Ming’ (play off of the planet Mongo from Flash Gordon)We’re going to have lots of code here. Hope you like Python!
  • #16: Someone is going to put weird data in your database.Or they will try.Catch them in the act.