MongoKit framework try to keep its simplicity when you manage mongodb in python. MongoKit was developed to be fast and light with KISS and DRY in mind. MongoKit brings structured schema and validation layer on top of the great pymongo driver. Discuss with us on Google group : http://groups.google.com/group/mongokit or follow the news on Twitter: http://twitter.com/namlook
In the mongokit.auth.User class '_id' and 'login' meant to be the same.
In [1]: from mongokit.auth import User
In [2]: me = User()
In [3]: me.login, me.email, me.password = 'Winnetou', 'mieszko.chowaniec@gmail.com', 'supersecret'
In [4]: me
Out [4]:
{'_id': 'Winnetou',
'user': {'email': 'mieszko.chowaniec@gmail.com',
'login': 'Winnetou',
'password': u'24f1ae1bd48d66a899a0929ad94643f4ac3d395276ee5135bacea9ee3f1a2746b2660b2f0421cd3f'}}
In [5]: me.validate()
InvalidDocument Traceback (most recent call last)
in ()
--> 1 me.validate()
/usr/local/lib/python2.7/dist-packages/mongokit/document.pyc in validate(self, auto_migrate)
227 # found when validating at **init** with autorefs
228 self._make_reference(self, self.structure)
--> 229 size = self.get_size()
230 (size_limit, size_limit_str) = self._get_size_limit()
231
/usr/local/lib/python2.7/dist-packages/mongokit/document.pyc in get_size(self)
261 except:
262 self._process_custom_type('bson', self, self.structure)
--> 263 size = len(BSON.encode(self))
264 self._process_custom_type('python', self, self.structure)
265 return size
/usr/local/lib/python2.7/dist-packages/bson/**init**.pyc in encode(cls, document, check_keys, uuid_subtype)
588 .. versionadded:: 1.9
589 """
--> 590 return cls(_dict_to_bson(document, check_keys, uuid_subtype))
591
592 def decode(self, as_class=dict,
InvalidDocument: Cannot encode object: {'login': 'Winnetou', 'password': u'24f1ae1bd48d66a899a0929ad94643f4ac3d395276ee5135bacea9ee3f1a2746b2660b2f0421cd3f', 'email': 'mieszko.chowaniec@gmail.com'}
In [6]: me.save()
---
InvalidDocument Traceback (most recent call last)
in ()
-->1 me.save()
/usr/local/lib/python2.7/dist-packages/mongokit/auth.py in save(self, _args, *_kwargs)
97 def save(self, _args, *_kwargs):
98 assert self['_id'] == self['user']['login']
---> 99 super(User, self).save(_args, *_kwargs)
/usr/local/lib/python2.7/dist-packages/mongokit/document.pyc in save(self, uuid, validate, safe, _args, *_kwargs)
418 """
419 if validate is True or (validate is None and self.skip_validation is False):
--> 420 self.validate(auto_migrate=False)
421 else:
422 if self.use_autorefs:
/usr/local/lib/python2.7/dist-packages/mongokit/document.pyc in validate(self, auto_migrate)
227 # found when validating at **init** with autorefs
228 self._make_reference(self, self.structure)
--> 229 size = self.get_size()
230 (size_limit, size_limit_str) = self._get_size_limit()
231
/usr/local/lib/python2.7/dist-packages/mongokit/document.pyc in get_size(self)
261 except:
262 self._process_custom_type('bson', self, self.structure)
--> 263 size = len(BSON.encode(self))
264 self._process_custom_type('python', self, self.structure)
265 return size
/usr/local/lib/python2.7/dist-packages/bson/**init**.pyc in encode(cls, document, check_keys, uuid_subtype)
588 .. versionadded:: 1.9
589 """
--> 590 return cls(_dict_to_bson(document, check_keys, uuid_subtype))
591
592 def decode(self, as_class=dict,
InvalidDocument: Cannot encode object: {'login': 'Winnetou', 'password': u'24f1ae1bd48d66a899a0929ad94643f4ac3d395276ee5135bacea9ee3f1a2746b2660b2f0421cd3f', 'email': 'mieszko.chowaniec@gmail.com'}
In the mongokit.auth.User class '_id' and 'login' meant to be the same. In [1]: from mongokit.auth import User In [2]: me = User() In [3]: me.login, me.email, me.password = 'Winnetou', 'mieszko.chowaniec@gmail.com', 'supersecret' In [4]: me Out [4]: {'_id': 'Winnetou', 'user': {'email': 'mieszko.chowaniec@gmail.com', 'login': 'Winnetou', 'password': u'24f1ae1bd48d66a899a0929ad94643f4ac3d395276ee5135bacea9ee3f1a2746b2660b2f0421cd3f'}}
In [5]: me.validate()
InvalidDocument Traceback (most recent call last)