+
80
-

mongodb如何选择自定义字段查询?

mongodb如何选择自定义字段查询?类似于mysql的select 字段 from


网友回复

+
0
-

通过projection来获取自己想要的字段,设为1表示获取,0表示不获取,代码如下:

<?php
$key = "bfw";
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");


$filter =[];
//通过projecttion来获取自己想要的字段,设为1表示获取,0表示不获取
$options = array("projection" => array("name" => 1));
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery("test.bfw", $query);
foreach ($cursor as $document) {
    var_dump($document);
}

我知道答案,我要回答