Author: Rick Copeland
What is Ming? MongoDB driver
MongoDB Terminology
Relational | MongoDB |
---|---|
Database | Databse |
Table | Collection |
Index | Index |
Row | Document |
Column | Field |
Example:
- Document Primary Key: ID in Relational DB
- UnixDateTime: ISODateTime('2012-09-17')
db.update({spec}, {update})
- At most one index is used for any given query/update
- Most indexes are B-tree based
- GeoSpatial indexes and queryies
- Full-text search
Mongodb uses shards
3 configurations
PyMongo
- Auto-generated _id on client-sides
- Cursor == Python Generator
- CRUD
.explain()
will expalin the query cursors- Aggregation
Why Ming?
- Data has a schema
- Migration
- Unit of work -- queue up the updates
Datastore and Session
- Define Schema
- Ming Models
Ming Bounus: MIM
- in memory partial pymongo implmentation
- Useful for unit tests, Does NOT actually touch the disk db
- Does NOT Scale
Ming ODM
- Session -> ODMSession
- collection.m ... -> MappedClass.query
- Session actually does stuff
- Track object identity
- Track object modifications
- Unit of work to save everything at once
Integration with python web frameworks
- ThreadLocalODMSession
- ming.odm.middleware.MingMiddleware
- flush
- clear
@something
@something_else
def foo():
pass
def foo():
pass
something_else(foo)
something(foo)
Another example:
@view(..)
def my_view():
...
def view(a, b):
def decorator(function):
function.a = a
function.b = b
return function
return decorator
def log(logger, message):
def decorator(function):
def wrapper(*args, **kwargs):
logger.info('ENTER:' + message)
try:
result = function(*args, **kwargs)
logger.info('EXIT (%r): ' + message, result)
return result
except Exception as err:
logger.info('EXCEPTION (%r): ' + message, err)
raise
return wrapper
return decorator
@log(logging.getLogger(__name__), 'Mylog')
def something(a,b):
pass
def something
_tmp0 = log(...)
something = _tmp0(something)
something == wrapper<...>