+
80
-

mongodb查询数据如何使用or和and?

mongodb查询数据如何使用or和and?

网友回复

+
0
-

<?php
//mongodb php7 $or 和 $and查询
$key = "bfw";
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

$value = new MongoDB\BSON\Regex(trim($key, '/'), 'i');
$filter["name"]="BFW";
//and查询

$filter['$or'] = [
    array(
        "name" => "BFW",
    ),
    array(
        "oid" => 2,
    ),

];

$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery("test.bfw", $query);
foreach ($cursor as $document) {
    var_dump($document);
}

我知道答案,我要回答