orm – Map a mongo collection into a python class

class mongotor.orm.collection.Collection

Collection is the base class

This class map a mongo collection into a python class. You only need to write a class and starts to use the orm advantages.

For example, a simple users collection can be mapping using:

>>> from mongotor.orm import collection, field
>>> class Users(collection.Collection):
>>>     __collection__ = 'users'
>>>     name = field.StringField()
save(*args, **kwargs)

Save a document

>>> user = Users()
>>> user.name = 'should be name'
>>> user.save()
Parameters:
  • safe (optional): safe insert operation
  • check_keys (optional): check if keys start with ‘$’ or contain ‘.’, raising InvalidName in either case
  • callback : method which will be called when save is finished
remove(*args, **kwargs)

Remove a document

Parameters:
  • safe (optional): safe remove operation
  • callback : method which will be called when remove is finished
update(*args, **kwargs)

Update a document

Parameters:
  • safe (optional): safe update operation
  • callback : method which will be called when update is finished
  • force: if True will overide full document

Previous topic

collection – A mongo collection

Next topic

errors – Mongotor errors

This Page