MongoDB\BSON\Regex::__construct

(mongodb >=1.0.0)

MongoDB\BSON\Regex::__constructDescription

Опис

public MongoDB\BSON\Regex::__construct ( string $pattern , string $flags )

Параметри

pattern

flags

Значення, що повертаються

Помилки/Винятки

Приклади

Приклад #1 MongoDB\BSON\Regex::__construct() example

<?php

/* ... */

?>

Наведений вище приклад виведе щось подібне до:

...

Прогляньте Також

add a note add a note

User Contributed Notes 1 note

up
5
Alejandro Wilcke
4 years ago
This matches with any fieldName that includes the string:
$mongoRegex = new MongoDB\BSON\Regex("$string", "i");

This matches with any fieldName that STARTS with the string:
$mongoRegex = new MongoDB\BSON\Regex("^$string", "i");

$cursor = $collection->find( [ 'fieldName' => $mongoRegex ] );

$docs = [];

foreach($cursor as $doc){
     $docs[] = $doc;
}

return $docs;
To Top