From 851e9878c52fc66e19bd3225fefcdca0671f3b0c Mon Sep 17 00:00:00 2001 From: Axel Haustant Date: Tue, 26 Sep 2017 15:36:56 +0200 Subject: [PATCH 1/2] Allow lazy connection (connect=False) with flat config This PR allows to declare a lazy connection with `MONGODB_CONNECT = False` because right now only the `MONGODB_SETTINGS` dict support this parameter --- flask_mongoengine/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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): From cf95ddd5bb536e68dda8e7c74e64eabf66607cbd Mon Sep 17 00:00:00 2001 From: Axel Haustant Date: Tue, 26 Sep 2017 15:42:00 +0200 Subject: [PATCH 2/2] Document the CONNECT=False parameter --- docs/index.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 ===============