MongoDB :: listCollections not working

As part of Symfony Doctrine, I use MongoDB as a database. I need to have a list of all the collections in the database.

I thought the ListCollections() method would give me this, as the name suggests and the documentation. Except that this function does not return me anything.

From Symfony PHP, I call the method as follows:

$this->get('doctrine_mongodb.odm.default_connection')->selectDatabase('database');

This gives me an instance of the Doctrine\MongoDB\Database class. This class has a listCollection() function, as follows:

 /** * Wrapper method for MongoDB::listCollections(). * * @see http://php.net/manual/en/mongodb.listcollections.php * @return array */ public function listCollections() { return $this->mongoDB->listCollections(); } 

Since the documentation assumes that this function should return the array it makes (but it is empty even if there are collections in my database).

So, I went deeper and looked at the ListCollections() documentation of the ListCollections() pecl plugin, which says:

 /** * (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) {} 

How to get all collection names in one database in Symfony 3.0.6?

Some important details:

  • Mongo version: 1.5.5
  • Symfony Version: 3.0.6
  • MongoDB Shell Version: 3.2.4
+6
source share
1 answer

Mongo 1.5.5 has a bug that creates this.

https://github.com/mongodb/mongo-php-driver-legacy/blob/1.5.5/db.c

Try updating the mongo extension to 1.6.14 and try again!

+2
source

All Articles