这与包含字符串的任何 fieldName 匹配
$mongoRegex = new MongoDB\BSON\Regex("$string", "i");
这与以字符串开头的任何 fieldName 匹配
$mongoRegex = new MongoDB\BSON\Regex("^$string", "i");
$cursor = $collection->find( [ 'fieldName' => $mongoRegex ] );
$docs = [];
foreach($cursor as $doc){
$docs[] = $doc;
}
return $docs;