【发布时间】:2017-03-10 16:54:11
【问题描述】:
我想从Collection 中的所有文档中获取数据。在我的情况下,数据是Color 字段。我想从Collection 中的所有文档中检索所有Color 字段值。是否可以在PHP 中使用MongoManager 类?我正在尝试这种方式;
$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$query = new MongoDB\Driver\Query([]);
$r = $mng->executeQuery("DB.Collection", $query);
$R = current($r->toArray());
if (!empty($R)) {
echo ($R->Color);
} else {
echo "Nothing found";
}
但它只给出一个字段。如何获取所有颜色字段?
【问题讨论】:
标签: php mongodb mongodb-query