在PHP7/HHVM的新MongoDB库中使用正则表达式

在PHP7/HHVM的新MongoDB库中使用正则表达式,php,regex,mongodb,Php,Regex,Mongodb,试图弄清楚如何在新版本中使用正则表达式 我没有找到使用MongoDB\BSON\Regex的真实示例,因此我提出了以下代码: $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); $bulk = new MongoDB\Driver\BulkWrite; $bulk->insert(['word' => ['word' => 'heelo']]); $bulk->insert(['word

试图弄清楚如何在新版本中使用正则表达式

我没有找到使用MongoDB\BSON\Regex的真实示例,因此我提出了以下代码:

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['word' => ['word' => 'heelo']]);
$bulk->insert(['word' => ['word' => 'hello']]);
$manager->executeBulkWrite('db.collection', $bulk);

$filter = ['word' => ['word' => new MongoDB\BSON\Regex("hello","i")]];

$query = new MongoDB\Driver\Query($filter);
$cursor = $manager->executeQuery('db.collection', $query);

foreach ($cursor as $document) {
    var_dump($document);
}

但它什么也没表现出来。有人知道如何使用它吗?

我找到了答案。我应该这样写查询:

$filter = ['word.word' => new MongoDB\BSON\Regex("hello","i")];
您好,
“i”
代表什么?在大多数正则表达式库中,“i”不区分大小写(或忽略大小写,但结果相同)。