Skip to content

Commit

Permalink
fix README + remove MongoKit referencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Namlook committed Aug 8, 2011
1 parent b83a1f4 commit dd302a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions README.rst
Expand Up @@ -37,14 +37,13 @@ Features
* json helpers
* GridFS support

Go to the full documentation_ .
.. Go to the full documentation_ .
.. _documentation : http://namlook.github.com/mongolite/

A quick example
===============

Document are enhanced python dictionary with a ``validate()`` method.
A Document declaration look like that::

>>> from mongolite import *
Expand All @@ -56,29 +55,43 @@ A Document declaration look like that::
... class BlogPost(Document):
... __database__ = 'test'
... __collection__ = 'example'
... structure = {
... skeleton = {
... 'title':unicode,
... 'body':unicode,
... 'author':unicode,
... 'date_creation':datetime.datetime,
... 'rank':int
... }
... optional = {
... 'tags': [unicode],
... }
... default_values = {'rank':0, 'date_creation':datetime.datetime.utcnow}
...

We fire a connection and register our objects.

>>> blogpost = con.BlogPost() # this use the db "test" from `__database__` and the collection "example" from `__collection__`
>>> blogpost # the skeleton is automatically generated
>>> blogpost # the skeleton is automatically generated (based on the skeleton attribute)
{'body': None, 'title': None, 'date_creation': datetime.datetime(...), 'rank': 0, 'author': None}
>>> blogpost['title'] = u'my title'
>>> blogpost['body'] = u'a body'
>>> blogpost['author'] = u'me'
>>> blogpost['tags'] = ['about me', 'first post']
>>> blogpost
{'body': u'a body', 'title': u'my title', 'date_creation': datetime.datetime(...), 'rank': 0, 'author': u'me'}
{'body': u'a body', 'title': u'my title', 'date_creation': datetime.datetime(...), 'rank': 0, 'author': u'me', 'tags': [u'about me', u'first post']}
>>> blogpost.save()

MongoLite is written on top of pymongo. All the pymongo's API is accessible and the results are wrapped into Document objects :
Note that, while fields in `skeleton` should be present in the document, fields in `optional` attribute are not generated by default. It aims to be for documentation only...

To access those fields, use the following convention:

**for fields in skeleton**::

>>> title = blogpost['title']

**for fields in optional**::

>>> tags = blogpost.get('tags', [])

MongoLite is written on top of pymongo. All the pymongo's API is accessible and the results are wrapped into Document objects:

>>> blogpost = con.BlogPost.find_one() # this is a blogpost object

Expand Down
2 changes: 1 addition & 1 deletion mongolite/master_slave_connection.py
Expand Up @@ -11,7 +11,7 @@
from mongolite.connection import CallableMixin, _iterables

class MasterSlaveConnection(PymongoMasterSlaveConnection):
""" Master-Slave support for MongoKit """
""" Master-Slave support for MongoLite """

def __init__(self, master, slaves=[]):
""" The MasterSlaveConnection is a wrapper around the
Expand Down

0 comments on commit dd302a0

Please sign in to comment.