這與包含字串的任何 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;