我想使用php获取monogoDB的所有集合。
使用波纹管代码我只能得到一个收藏集。
<?php
$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$listdatabases = new MongoDB\Driver\Command(["listCollections" => 1]);
$res = $manager->executeCommand("mydatabasename", $listdatabases);
$collections = current($res->toArray());
print_r($collections);
stdClass Object
(
[name] => collectionname
[type] => collection
[options] => stdClass Object
(
)
[info] => stdClass Object
(
[readOnly] =>
[uuid] => MongoDB\BSON\Binary Object
(
[data] => �����B���tqIB
[type] => 4
)
)
[idIndex] => stdClass Object
(
[v] => 2
[key] => stdClass Object
(
[_id] => 1
)
[name] => _id_
[ns] => collectionname
)
)
MongoDB版本:3.4.16
Php版本:7.1
答案 0 :(得分:0)
您只需要从
中删除电流$collections = current($res->toArray());
您将获得所有收藏。应该是
$collections = $res->toArray();