From 921c9f876cd0d529f163592cfef4ac300c46ae5f Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Fri, 21 Jul 2023 23:30:18 +0800 Subject: [PATCH] Raise exception when database name not found --- function.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/function.py b/function.py index c4f1063..05e1e12 100644 --- a/function.py +++ b/function.py @@ -26,7 +26,10 @@ if not (tokens.mongodb_name and tokens.mongodb_url): try: mongodb = MongoClient(host=tokens.mongodb_url, serverSelectionTimeoutMS=5000) mongodb.server_info() + if tokens.mongodb_name not in mongodb.list_database_names(): + raise Exception(f"{tokens.mongodb_name} does not exist in your mongoDB!") print("Successfully connected to MongoDB!") + except Exception as e: raise Exception("Not able to connect MongoDB! Reason:", e)