Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix README + remove MongoKit referencies

  • Loading branch information...
commit dd302a0c9fc1609942480a5b6cf25c77ef8e684d 1 parent b83a1f4
@namlook authored
Showing with 22 additions and 9 deletions.
  1. +21 −8 README.rst
  2. +1 −1  mongolite/master_slave_connection.py
View
29 README.rst
@@ -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 *
@@ -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
View
2  mongolite/master_slave_connection.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.