繁体   English   中英

如何使用“新 MongoDB\\Driver\\Manager”驱动程序在 php 中获取集合 {Mongodb} 列表

[英]how to get list of collection {Mongodb} in php using 'new MongoDB\Driver\Manager' driver

我想使用 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

你只需要从

$collections = current($res->toArray());

您将获得所有收藏。 它应该是

$collections = $res->toArray();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM