From d5fa816ebbab56b76255614872f03ad02223b518 Mon Sep 17 00:00:00 2001 From: KeepingRunning <1599949878@qq.com> Date: Sun, 30 Mar 2025 09:46:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ft:=20=E5=A2=9E=E5=8A=A0MongoDB=20SRV?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E6=95=B0=E6=8D=AE=E5=BA=93URI=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | Bin 672 -> 682 bytes src/common/database.py | 9 ++++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0dfd751484930ec11fed6da3b69ff72e6f5be121..76e16077faa4e80d647ddafcb2cf1bc4592ac629 100644 GIT binary patch delta 24 gcmZ3$x{7teI?iZ@Vum7yGKSd6^^Bq$58Yz~0AY*>DF6Tf delta 10 ScmZ3*x`1`Ux{W(NF#-S?l?3kq diff --git a/src/common/database.py b/src/common/database.py index a3e5b4e3..f038955b 100644 --- a/src/common/database.py +++ b/src/common/database.py @@ -15,9 +15,12 @@ def __create_database_instance(): password = os.getenv("MONGODB_PASSWORD") auth_source = os.getenv("MONGODB_AUTH_SOURCE") - if uri and uri.startswith("mongodb://"): - # 优先使用URI连接 - return MongoClient(uri) + if uri: + # Support both standard mongodb:// and mongodb+srv:// connection strings + if uri.startswith(("mongodb://", "mongodb+srv://")): + return MongoClient(uri) + else: + raise ValueError("Invalid MongoDB URI. Must start with 'mongodb://' or 'mongodb+srv://'") if username and password: # 如果有用户名和密码,使用认证连接 From 2835d4926b34dc130c7ce8d2b5bc8bebdf14e178 Mon Sep 17 00:00:00 2001 From: KeepingRunning <1599949878@qq.com> Date: Sun, 30 Mar 2025 10:45:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=8F=90=E4=BE=9B=E6=9B=B4=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E7=9A=84=E6=8A=A5=E9=94=99=E6=8F=90=E7=A4=BA=E5=B9=B6?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E6=B3=A8=E9=87=8A=E9=A3=8E=E6=A0=BC=E5=92=8C?= =?UTF-8?q?=E5=8E=9F=E4=BB=A3=E7=A0=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/database.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/database.py b/src/common/database.py index f038955b..ee0ead0b 100644 --- a/src/common/database.py +++ b/src/common/database.py @@ -16,11 +16,15 @@ def __create_database_instance(): auth_source = os.getenv("MONGODB_AUTH_SOURCE") if uri: - # Support both standard mongodb:// and mongodb+srv:// connection strings + # 支持标准mongodb://和mongodb+srv://连接字符串 if uri.startswith(("mongodb://", "mongodb+srv://")): return MongoClient(uri) else: - raise ValueError("Invalid MongoDB URI. Must start with 'mongodb://' or 'mongodb+srv://'") + raise ValueError( + "Invalid MongoDB URI format. URI must start with 'mongodb://' or 'mongodb+srv://'. " + "For MongoDB Atlas, use 'mongodb+srv://' format. " + "See: https://www.mongodb.com/docs/manual/reference/connection-string/" + ) if username and password: # 如果有用户名和密码,使用认证连接