Added SwitchDB context manager (#106)
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user