Skip to content

Commit 47d265b

Browse files
authored
Merge pull request #321 from noirbizarre/connect-parameter
Connect parameter
2 parents 5dc1dff + cf95ddd commit 47d265b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

docs/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ Connection settings may also be provided individually by prefixing the setting w
7474
app.config['MONGODB_USERNAME'] = 'webapp'
7575
app.config['MONGODB_PASSWORD'] = 'pwd123'
7676

77+
By default flask-mongoengine open the connection when extension is instanciated but you can configure it
78+
to open connection only on first database access by setting the ``MONGODB_SETTINGS['connect']`` parameter
79+
or its ``MONGODB_CONNECT`` flat equivalent to ``False``::
80+
81+
app.config['MONGODB_SETTINGS'] = {
82+
'host': 'mongodb://localhost/database_name',
83+
'connect': False,
84+
}
85+
# or
86+
app.config['MONGODB_CONNECT'] = False
7787

7888
Custom Queryset
7989
===============

flask_mongoengine/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
MONGODB_CONF_VARS = ('MONGODB_ALIAS', 'MONGODB_DB', 'MONGODB_HOST', 'MONGODB_IS_MOCK',
11-
'MONGODB_PASSWORD', 'MONGODB_PORT', 'MONGODB_USERNAME')
11+
'MONGODB_PASSWORD', 'MONGODB_PORT', 'MONGODB_USERNAME', 'MONGODB_CONNECT')
1212

1313

1414
class InvalidSettingsError(Exception):

0 commit comments

Comments
 (0)