Skip to content

Commit

Permalink
improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bagerard committed Dec 28, 2022
1 parent 61cf36e commit f9b6218
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mongoengine/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ def disconnect(alias=DEFAULT_CONNECTION_NAME):

connection = _connections.pop(alias, None)
if connection:
# Only close the client if we're removing the final reference.
# Use 'is' instead of 'in' or '==' to ensure the clients are
# the same instance.
# MongoEngine may share the same MongoClient across multiple aliases
# if connection settings are the same so we only close
# the client if we're removing the final reference.
# Important to use 'is' instead of '==' because clients connected to the same cluster
# will compare equal even with different options
if all(connection is not c for c in _connections.values()):
connection.close()

Expand Down

0 comments on commit f9b6218

Please sign in to comment.