Refactor MongoClient function to enhance configuration handling and preserve caller arguments

This commit is contained in:
2026-04-12 19:18:30 +02:00
parent 53575c1876
commit 57f6d2f8e7
+14 -6
View File
@@ -178,9 +178,17 @@ if not os.path.isabs(LOGS_FOLDER):
def MongoClient(*args, **kwargs):
"""Return a lightweight MongoDB client configured from this settings module."""
kwargs.setdefault('maxPoolSize', 10)
kwargs.setdefault('minPoolSize', 0)
kwargs.setdefault('connectTimeoutMS', 5000)
kwargs.setdefault('serverSelectionTimeoutMS', 5000)
kwargs.setdefault('retryWrites', True)
return _PyMongoClient(MONGODB_HOST, MONGODB_PORT, *args, **kwargs)
client_kwargs = {
'maxPoolSize': 10,
'minPoolSize': 0,
'connectTimeoutMS': 5000,
'serverSelectionTimeoutMS': 5000,
'retryWrites': True,
}
client_kwargs.update(kwargs)
# Preserve caller-provided positional host/port arguments.
# If none are passed, use configured defaults.
if args:
return _PyMongoClient(*args, **client_kwargs)
return _PyMongoClient(MONGODB_HOST, MONGODB_PORT, **client_kwargs)