diff --git a/docs/index.rst b/docs/index.rst index 1017140b..ccedf171 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -74,6 +74,16 @@ Connection settings may also be provided individually by prefixing the setting w app.config['MONGODB_USERNAME'] = 'webapp' app.config['MONGODB_PASSWORD'] = 'pwd123' +By default flask-mongoengine open the connection when extension is instanciated but you can configure it +to open connection only on first database access by setting the ``MONGODB_SETTINGS['connect']`` parameter +or its ``MONGODB_CONNECT`` flat equivalent to ``False``:: + + app.config['MONGODB_SETTINGS'] = { + 'host': 'mongodb://localhost/database_name', + 'connect': False, + } + # or + app.config['MONGODB_CONNECT'] = False Custom Queryset =============== diff --git a/flask_mongoengine/connection.py b/flask_mongoengine/connection.py index bbeda7f9..96b66ce2 100644 --- a/flask_mongoengine/connection.py +++ b/flask_mongoengine/connection.py @@ -8,7 +8,7 @@ MONGODB_CONF_VARS = ('MONGODB_ALIAS', 'MONGODB_DB', 'MONGODB_HOST', 'MONGODB_IS_MOCK', - 'MONGODB_PASSWORD', 'MONGODB_PORT', 'MONGODB_USERNAME') + 'MONGODB_PASSWORD', 'MONGODB_PORT', 'MONGODB_USERNAME', 'MONGODB_CONNECT') class InvalidSettingsError(Exception):