From 1218ba0b3c250248450d7d8683b29323b647cea6 Mon Sep 17 00:00:00 2001 From: TPV Date: Fri, 21 Aug 2026 08:21:57 -0700 Subject: [PATCH] added optional mongo client for already configured monitors --- src/monitor_utils/database.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/monitor_utils/database.py b/src/monitor_utils/database.py index ffb2e90..68481b8 100644 --- a/src/monitor_utils/database.py +++ b/src/monitor_utils/database.py @@ -29,17 +29,23 @@ NO_MSRP_PRIORITY = 6 NEW_LISTING_PRIORITY = 6 -def get_collection(collection_name: str) -> AsyncIOMotorCollection: +def get_collection( + collection_name: str, mongo_client: AsyncIOMotorClient = None +) -> AsyncIOMotorCollection: """Return the named collection from the shared client's database. Args: collection_name: Name of the collection to return. + mongo_client: optional client for projects with already configured client Returns: The requested collection. """ - return get_mongo_client()[MONGO_DATABASE_NAME][collection_name] + if mongo_client is None: + mongo_client = get_mongo_client() + + return mongo_client[MONGO_DATABASE_NAME][collection_name] def resolve_alerts_collection(