Skip to content

Instantly share code, notes, and snippets.

@namlook
Created October 20, 2010 10:00
Show Gist options
  • Save namlook/636126 to your computer and use it in GitHub Desktop.
Save namlook/636126 to your computer and use it in GitHub Desktop.
allow to access Document via the db
class MyDoc(Document):
collection_name = "mydoc"
structure = {
'foo': unicode,
'bar': int,
}
con = Connection()
con.register([MyDoc])
db = con.mydb
# this will be allowed and will use the `collection_name` attribute
doc = db.MyDoc()
# but this is also supported
doc = db.mycol.MyDoc()
# if the collection is different with the value of `collection_name`, a warning is raised in logging:
doc = db.othercol.MyDoc()
# Warning : the collection "othercol" is used instead of "mydoc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment