调整数据库地址
This commit is contained in:
@@ -7,11 +7,11 @@ command-format = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# MongoDB 连接
|
# MongoDB 连接
|
||||||
mongo_uri = "mongodb+srv://cluster0.8mosa.mongodb.net/sehuatang?retryWrites=true&w=majority"
|
mongo_uri = "mongodb+srv://readonly:cS9NSuiJ1ebHnUL0@cluster0.8mosa.mongodb.net/sehuatang?retryWrites=true&w=majority"
|
||||||
db = "sehuatang"
|
db = "sehuatang"
|
||||||
collections = ["asia_codeless_originate", "asia_mosaic_originate"]
|
collections = ["asia_codeless_originate", "asia_mosaic_originate"]
|
||||||
|
|
||||||
# 尝试匹配的字段名(存在其一即可)
|
# 尝试匹配的字段名(存在其一即可)
|
||||||
search_fields = ["number", "code", "番号"]
|
search_fields = ["number"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,13 +67,13 @@ class FanhaoSearchPlugin(MessagePluginInterface):
|
|||||||
|
|
||||||
self.mongo_uri = cfg.get(
|
self.mongo_uri = cfg.get(
|
||||||
"mongo_uri",
|
"mongo_uri",
|
||||||
"mongodb+srv://cluster0.8mosa.mongodb.net/sehuatang?retryWrites=true&w=majority",
|
"mongodb+srv://readonly:cS9NSuiJ1ebHnUL0@cluster0.8mosa.mongodb.net/sehuatang?retryWrites=true&w=majority",
|
||||||
)
|
)
|
||||||
self.mongo_db_name = cfg.get("db", "sehuatang")
|
self.mongo_db_name = cfg.get("db", "sehuatang")
|
||||||
self.collections = cfg.get(
|
self.collections = cfg.get(
|
||||||
"collections", ["asia_codeless_originate", "asia_mosaic_originate"]
|
"collections", ["asia_codeless_originate", "asia_mosaic_originate"]
|
||||||
)
|
)
|
||||||
self.search_fields = cfg.get("search_fields", ["number", "code", "番号"]) # 可能的字段名
|
self.search_fields = cfg.get("search_fields", ["number"]) # 可能的字段名
|
||||||
|
|
||||||
# 延迟连接,在首次查询时连接,避免初始化阻塞
|
# 延迟连接,在首次查询时连接,避免初始化阻塞
|
||||||
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
||||||
@@ -121,12 +121,27 @@ class FanhaoSearchPlugin(MessagePluginInterface):
|
|||||||
# 探活
|
# 探活
|
||||||
self.mongo_client.admin.command("ping")
|
self.mongo_client.admin.command("ping")
|
||||||
self.mongo_db = self.mongo_client.get_database(self.mongo_db_name)
|
self.mongo_db = self.mongo_client.get_database(self.mongo_db_name)
|
||||||
|
# 打印可见的数据库
|
||||||
|
try:
|
||||||
|
dbs = self.mongo_client.list_database_names()
|
||||||
|
self.LOG.info(f"[{self.name}] 可见数据库={dbs}")
|
||||||
|
except Exception as e:
|
||||||
|
self.LOG.warning(f"[{self.name}] 获取数据库列表失败: {e}")
|
||||||
try:
|
try:
|
||||||
colls = self.mongo_db.list_collection_names()
|
colls = self.mongo_db.list_collection_names()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
colls = []
|
colls = []
|
||||||
self.LOG.warning(f"[{self.name}] 获取集合列表失败: {e}")
|
self.LOG.warning(f"[{self.name}] 获取集合列表失败: {e}")
|
||||||
self.LOG.info(f"[{self.name}] MongoDB连接成功,集合={colls}")
|
self.LOG.info(f"[{self.name}] MongoDB连接成功,集合={colls}")
|
||||||
|
# 对配置集合进行计数探测
|
||||||
|
for cname in self.collections:
|
||||||
|
try:
|
||||||
|
c = self.mongo_db.get_collection(cname)
|
||||||
|
# 尝试快速计数(可能返回估算值,但足够判断可见性)
|
||||||
|
cnt = c.estimated_document_count()
|
||||||
|
self.LOG.info(f"[{self.name}] 集合探测 {self.mongo_db_name}.{cname} 文档数≈{cnt}")
|
||||||
|
except Exception as e:
|
||||||
|
self.LOG.warning(f"[{self.name}] 集合探测失败 {self.mongo_db_name}.{cname}: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"[{self.name}] MongoDB连接失败: {e}")
|
self.LOG.error(f"[{self.name}] MongoDB连接失败: {e}")
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user