Change lines 35 and 230 of the directory vendor/tothink/think-mongo/src/Builder.php. An official suggestion has been submitted. Whether to change it or not depends on whether it is important or not. You can change it if you use it yourself.
Add two fuzzy query methods like_first for all queries starting with the query string $value, and like_last for all queries ending with $value. The source code changes are as follows! protected $exp = ['<>' => 'ne', '=' => '=', '>' => 'gt', '>=' => 'gte ', '<' => 'lt', '<=' => 'lte', 'in' => 'in', 'not in' => 'nin', 'nin' = > 'nin', 'mod' => 'mod', 'exists' => 'exists', 'regex' => 'regex', 'type' => 'type', 'all' = > 'all', '> time' => '> time', '< time' => '< time', 'between time' => 'between time', 'not between time ' => 'not between time', 'notbetween time' => 'not between time', 'like' => 'like','like_first'=>'like_first','like_last'=>' like_last'];
} elseif ('like' == $exp) {<br>
// Fuzzy query adopts regular method<br>
$query[$key] = $value instanceof Regex ? $value : new Regex("$value", 'i');<br>
}elseif ('like_first' == $exp) { <br>
// Fuzzy query uses regular mode to query all data starting with $value <br>
$query[$key] = $value instanceof Regex ? $value : new Regex("^$value", 'i');<br>
}elseif ('like_last' == $exp) {<br>
// Fuzzy query uses regular mode to query all data ending with $value <br>
$query[$key] = $value instanceof Regex ? $value : new Regex("$value$", 'i');<br>
}
The usage method is the same as like. As follows: where(['like',$value]); /*Global fuzzy query*/<br>
where(['like_first',$value]); /*All data starting with $value*/<br>
where(['like_last',$value]); /*All data ending with $value*/