在新的MongoDB库中使用Regex for PHP7/HHVM

Ale*_*kin 2 php regex mongodb

试图弄清楚如何在新的MongoDB库中使用Regex

我没有找到使用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);
}
Run Code Online (Sandbox Code Playgroud)

但它没有显示任何内容 有谁知道如何使用它?

Ale*_*kin 7

我找到了答案.我应该写如下查询:

$filter = ['word.word' => new MongoDB\BSON\Regex("hello","i")];
Run Code Online (Sandbox Code Playgroud)