diff --git a/AUTHORS b/AUTHORS index 095c4007..1ac192cf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -86,4 +86,5 @@ that much better: * jwilder * Joe Shaw * Adam Flynn + * Ankhbayar * Jan Schrewe diff --git a/docs/changelog.rst b/docs/changelog.rst index 81b34306..003a59fd 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Changes in dev ============== +- Added db_alias support to individual documents - Fixed GridFS documents can now be pickled - Added Now raises an InvalidDocumentError when declaring multiple fields with the same db_field - Added InvalidQueryError when calling with_id with a filter diff --git a/docs/guide/connecting.rst b/docs/guide/connecting.rst index a51d68e6..470dcb88 100644 --- a/docs/guide/connecting.rst +++ b/docs/guide/connecting.rst @@ -30,3 +30,24 @@ for the connection - if no `alias` is provided then "default" is used. In the background this uses :func:`~mongoengine.register_connection` to store the data and you can register all aliases up front if required. + +Individual documents can also support multiple databases by providing a +`db_alias` in their meta data. This allows :class:`~pymongo.dbref.DBRef` objects +to point across databases and collections. Below is an example schema, using +3 different databases to store data:: + + class User(Document): + name = StringField() + + meta = {"db_alias": "user-db"} + + class Book(Document): + name = StringField() + + meta = {"db_alias": "book-db"} + + class AuthorBooks(Document): + author = ReferenceField(User) + book = ReferenceField(Book) + + meta = {"db_alias": "users-books-db"}