Updated docs

This commit is contained in:
Ross Lawley 2014-01-13 16:57:49 +00:00
parent 516591fe88
commit c5cc4b7867
2 changed files with 16 additions and 0 deletions

View File

@ -38,6 +38,7 @@ Context Managers
================ ================
.. autoclass:: mongoengine.context_managers.switch_db .. autoclass:: mongoengine.context_managers.switch_db
.. autoclass:: mongoengine.context_managers.switch_collection
.. autoclass:: mongoengine.context_managers.no_dereference .. autoclass:: mongoengine.context_managers.no_dereference
.. autoclass:: mongoengine.context_managers.query_counter .. autoclass:: mongoengine.context_managers.query_counter

View File

@ -100,3 +100,18 @@ access to the same User document across databases::
.. note:: Make sure any aliases have been registered with .. note:: Make sure any aliases have been registered with
:func:`~mongoengine.register_connection` before using the context manager. :func:`~mongoengine.register_connection` before using the context manager.
There is also a switch collection context manager as well. The
:class:`~mongoengine.context_managers.switch_collection` context manager allows
you to change the collection for a given class allowing quick and easy
access to the same Group document across collection::
from mongoengine.context_managers import switch_db
class Group(Document):
name = StringField()
Group(name="test").save() # Saves in the default db
with switch_collection(Group, 'group2000') as Group:
Group(name="hello Group 2000 collection!").save() # Saves in group2000 collection