Added SwitchDB context manager (#106)
This commit is contained in:
parent
6d68ad735c
commit
e5e88d792e
5 changed files with 85 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ Connecting
|
|||
|
||||
.. autofunction:: mongoengine.connect
|
||||
.. autofunction:: mongoengine.register_connection
|
||||
.. autoclass:: mongoengine.SwitchDB
|
||||
|
||||
Documents
|
||||
=========
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ Changes in 0.8.X
|
|||
- Fixed inheritance and unique index creation (#140)
|
||||
- Fixed reverse delete rule with inheritance (#197)
|
||||
- Fixed validation for GenericReferences which havent been dereferenced
|
||||
- Added SwitchDB context manager (#106)
|
||||
|
||||
Changes in 0.7.9
|
||||
================
|
||||
|
|
|
|||
|
|
@ -69,3 +69,21 @@ to point across databases and collections. Below is an example schema, using
|
|||
book = ReferenceField(Book)
|
||||
|
||||
meta = {"db_alias": "users-books-db"}
|
||||
|
||||
|
||||
Switch Database Context Manager
|
||||
===============================
|
||||
|
||||
Sometimes you might want to switch the database to query against for a class.
|
||||
The SwitchDB context manager allows you to change the database alias for a
|
||||
class eg ::
|
||||
|
||||
from mongoengine import SwitchDB
|
||||
|
||||
class User(Document):
|
||||
name = StringField()
|
||||
|
||||
meta = {"db_alias": "user-db"}
|
||||
|
||||
with SwitchDB(User, 'archive-user-db') as User:
|
||||
User(name="Ross").save() # Saves the 'archive-user-db'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue