From e2e330fedd3fc579de12132ed74cd1b13cfec4cb Mon Sep 17 00:00:00 2001 From: huangbinghe Date: Mon, 7 Apr 2025 09:11:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3DbConnect.php=E7=AC=AC40?= =?UTF-8?q?=E8=A1=8CautoInc=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用mongo驱动时 `think\model\concern\DbConnect` 第40行需要调用mongo的自动递增主键的方法,会报方法不存在的错误, 补充了这3个对应方法解决此bug --- src/db/Mongo.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/db/Mongo.php b/src/db/Mongo.php index 748c4d94..9934a96e 100644 --- a/src/db/Mongo.php +++ b/src/db/Mongo.php @@ -755,4 +755,35 @@ public function getFieldType(string $field) return $fieldType[$field] ?? null; } + + /** + * 获取字段类型 + * + * @return array + */ + public function getType() + { + return $this->getFieldsType(); + } + + /** + * 获取自增主键 + * + * @return string + */ + public function getAutoInc() + { + return ''; + } + + /** + * 设置自增主键 + * + * @param string $autoInc + * @return static + */ + public function autoInc(?string $autoInc) + { + return $this; + } } From 8cb7a12e72438ff7b354da72f87e612dabfdc3f6 Mon Sep 17 00:00:00 2001 From: huangbinghe Date: Fri, 21 Nov 2025 11:49:03 +0800 Subject: [PATCH 2/2] Improve handling of 'like' queries in Mongo.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor 'like' query handling to escape non-regex strings before creating Regex object. mongodb的like查询,如果$value是字符串判断是否正则表达式,否则做一下正则特殊字符转义处理,避免$value中包含了正则特殊字符,导致查询未达预期 --- src/db/builder/Mongo.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/db/builder/Mongo.php b/src/db/builder/Mongo.php index d2c98d8a..e6df2ea4 100644 --- a/src/db/builder/Mongo.php +++ b/src/db/builder/Mongo.php @@ -289,7 +289,14 @@ protected function parseWhereItem(Query $query, $field, $val): array $result['$where'] = $value instanceof Javascript ? $value : new Javascript($value); } elseif ('like' == $exp) { // 模糊查询 采用正则方式 - $result[$key] = $value instanceof Regex ? $value : new Regex($value, 'i'); + if (!($value instanceof Regex)) { + if (strpos($value,'/') !== 0){ + // 非正则表达式,做一下字符转义处理 + $value = preg_quote($value); + } + $value = new Regex($value,'i'); + } + $result[$key] = $value; } elseif (in_array($exp, ['nin', 'in'])) { // IN 查询 $value = is_array($value) ? $value : explode(',', $value);