在Symfony Doctrine中我使用MongoDB作为数据库。我需要有一个数据库中所有集合的列表。
我认为方法ListCollections()
会给我这些名称和文档建议。
除了这个功能,根本不会给我任何回报。
从Symfony PHP我调用这样的方法:
$this->get('doctrine_mongodb.odm.default_connection')->selectDatabase('database');
这给了我一个类Doctrine\MongoDB\Database
的实例
该类具有如下所述的函数listCollection()
:
/**
* Wrapper method for MongoDB::listCollections().
*
* @see http://php.net/manual/en/mongodb.listcollections.php
* @return array
*/
public function listCollections()
{
return $this->mongoDB->listCollections();
}
正如文档所示,这个函数应该返回一个它所做的数组(即使我的数据库中有集合,它也是空的。)
所以我更深入地看了一下mongo pecl插件listCollections()
的文档,其中说明了:
/**
* (PECL mongo >= 0.9.0)<br/>
* Get a list of collections in this database
* @link http://www.php.net/manual/en/mongodb.listcollections.php
* @param bool $includeSystemCollections [optional] <p>Include system collections.</p>
* @return array Returns a list of MongoCollections.
*/
public function listCollections($includeSystemCollections = false) {}
如何在Symfony 3.0.6中的一个数据库中获取所有集合名称?
一些关键细节:
答案 0 :(得分:2)
Mongo 1.5.5有一个创建此错误的错误。
https://github.com/mongodb/mongo-php-driver-legacy/blob/1.5.5/db.c
尝试将mongo扩展名更新为1.6.14,然后重试!