mirror of https://github.com/Mai-with-u/MaiBot.git
fix: 提供更详细的报错提示并保持注释风格和原代码一致
parent
d5fa816ebb
commit
2835d4926b
|
|
@ -16,11 +16,15 @@ def __create_database_instance():
|
||||||
auth_source = os.getenv("MONGODB_AUTH_SOURCE")
|
auth_source = os.getenv("MONGODB_AUTH_SOURCE")
|
||||||
|
|
||||||
if uri:
|
if uri:
|
||||||
# Support both standard mongodb:// and mongodb+srv:// connection strings
|
# 支持标准mongodb://和mongodb+srv://连接字符串
|
||||||
if uri.startswith(("mongodb://", "mongodb+srv://")):
|
if uri.startswith(("mongodb://", "mongodb+srv://")):
|
||||||
return MongoClient(uri)
|
return MongoClient(uri)
|
||||||
else:
|
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:
|
if username and password:
|
||||||
# 如果有用户名和密码,使用认证连接
|
# 如果有用户名和密码,使用认证连接
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue