Home > php教程 > php手册 > Thinkphp5.0mongodb unilateral query [with modified source code]

Thinkphp5.0mongodb unilateral query [with modified source code]

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-15 16:49:59
Original
1440 people have browsed it

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*/

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template