mirror of https://github.com/Mai-with-u/MaiBot.git
ft: 增加MongoDB SRV格式数据库URI支持
parent
256bfcf5c2
commit
d5fa816ebb
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
|
|
@ -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:
|
||||
# 如果有用户名和密码,使用认证连接
|
||||
|
|
|
|||
Loading…
Reference in New Issue