By Peter Bengtsson, Fry-IT
www.peterbe.com
But I've never written my own ORM, templating language, web framework or blog engine
Compared to...
Bob Ippolito's talk Drop ACID and think about data PyCon 2009
But what does it mean to use MongoDB?
Next step: Implications
4bebe6e26b2ded78ec00000a
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
time | machine | pid | inc |
Let's assume we decide to use MongoDB
Next step: Python
pymongo!
(TxMongo - asynchronous variant based on Twisted)
Next step: "ORM"
Next step: Django
Next step: code
from ming.datastore import DataStore from ming import Session from ming import Document, Field, schema bind = DataStore('mongo://localhost:27017/tutorial') session = Session(bind) class WikiPage(Document): class __mongometa__: session = session name = 'wiki_page' _id = Field(schema.ObjectId) title = Field(str) text = Field(str, if_missing='') metadata = Field(dict( tags=[str], revisions=[int]))
>>> for page in WikiPage.m.find() >>> print page['title']
from django_mongokit import connection from django_mongokit.document import DjangoDocument class WikiPage(DjangoDocument): structure = {'title': unicode, 'text': unicode, 'metadata': {'tags':[unicode], 'revisions':[int]}, } required_fields = ['title'] default_values = {'text': u""} connection.register([WikiPage])
>>> collection = get_database()['wiki'] >>> for page in collection.WikiPage.find(): >>> print page.title
from mongoengine import * class Metadata(EmbeddedDocument): tags = ListField(StringField()) revisions = ListField(IntField()) class WikiPage(Document): title = StringField(required=True) text = StringField() metadata = EmbeddedDocumentField(Metadata)
>>> for page in WikiPage.objects: >>> print page.title
Next step: why
import *