From d045ef7b1fb1887db9e7fff67eeff2ab38b29aec Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 10 Sep 2025 16:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/fanhao_search/config.toml | 4 ++-- plugins/fanhao_search/main.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/fanhao_search/config.toml b/plugins/fanhao_search/config.toml index 85b791c..6909067 100644 --- a/plugins/fanhao_search/config.toml +++ b/plugins/fanhao_search/config.toml @@ -7,11 +7,11 @@ command-format = """ """ # 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" collections = ["asia_codeless_originate", "asia_mosaic_originate"] # 尝试匹配的字段名(存在其一即可) -search_fields = ["number", "code", "番号"] +search_fields = ["number"] diff --git a/plugins/fanhao_search/main.py b/plugins/fanhao_search/main.py index 47f61f2..b9b3cbf 100644 --- a/plugins/fanhao_search/main.py +++ b/plugins/fanhao_search/main.py @@ -67,13 +67,13 @@ class FanhaoSearchPlugin(MessagePluginInterface): self.mongo_uri = cfg.get( "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.collections = cfg.get( "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}") @@ -121,12 +121,27 @@ class FanhaoSearchPlugin(MessagePluginInterface): # 探活 self.mongo_client.admin.command("ping") 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: colls = self.mongo_db.list_collection_names() except Exception as e: colls = [] self.LOG.warning(f"[{self.name}] 获取集合列表失败: {e}") 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: self.LOG.error(f"[{self.name}] MongoDB连接失败: {e}") raise