Example #1
0
 /**
  * @before
  */
 protected function setUpMongoClient()
 {
     $client = new Client();
     $this->database = $client->selectDatabase('yadm_test');
     foreach ($this->database->listCollections() as $collectionInfo) {
         if ('system.indexes' == $collectionInfo->getName()) {
             continue;
         }
         $this->database->dropCollection($collectionInfo->getName());
     }
 }
 /**
  * Drop the collection if it exists.
  *
  * @param Collection $collection
  */
 protected function dropCollectionIfItExists(Collection $collection)
 {
     $database = new Database($this->manager, $collection->getDatabaseName());
     $collections = $database->listCollections(array('filter' => array('name' => $collection->getCollectionName())));
     if (iterator_count($collections) > 0) {
         $this->assertCommandSucceeded($collection->drop());
     }
 }
Example #3
0
 /**
  * (PECL mongo &gt;= 1.3.0)<br/>
  * @link http://www.php.net/manual/en/mongodb.getcollectionnames.php
  * Get all collections from this database
  * @return array Returns the names of the all the collections in the database as an
  * {@link http://www.php.net/manual/en/language.types.array.php array}.
  */
 public function getCollectionNames(array $options = [])
 {
     if (is_bool($options)) {
         $options = ['includeSystemCollections' => $options];
     }
     $collections = $this->db->listCollections($options);
     $getCollectionName = function (CollectionInfo $collectionInfo) {
         return $collectionInfo->getName();
     };
     return array_map($getCollectionName, (array) $collections);
 }
Example #4
0
 /**
  * Get all collections from this database
  *
  * @link http://www.php.net/manual/en/mongodb.getcollectionnames.php
  * @param array $options An array of options for listing the collections.
  * @return array Returns the names of the all the collections in the database as an array
  */
 public function getCollectionNames(array $options = [])
 {
     // The includeSystemCollections option is no longer supported
     if (isset($options['includeSystemCollections'])) {
         unset($options['includeSystemCollections']);
     }
     $collections = $this->db->listCollections($options);
     $getCollectionName = function (CollectionInfo $collectionInfo) {
         return $collectionInfo->getName();
     };
     return array_map($getCollectionName, iterator_to_array($collections));
 }
Example #5
0
 /**
  * Get all collections from this database
  *
  * @link http://www.php.net/manual/en/mongodb.getcollectionnames.php
  * @param array $options An array of options for listing the collections.
  * @return array Returns the names of the all the collections in the database as an array
  */
 public function getCollectionNames(array $options = [])
 {
     // The includeSystemCollections option is no longer supported
     if (isset($options['includeSystemCollections'])) {
         unset($options['includeSystemCollections']);
     }
     try {
         $collections = $this->db->listCollections($options);
     } catch (\MongoDB\Driver\Exception\Exception $e) {
         ExceptionConverter::toLegacy($e);
     }
     $getCollectionName = function (CollectionInfo $collectionInfo) {
         return $collectionInfo->getName();
     };
     return array_map($getCollectionName, iterator_to_array($collections));
 }
Example #6
0
 /**
  * Get all collections from this database
  *
  * @link http://www.php.net/manual/en/mongodb.getcollectionnames.php
  * @param array $options An array of options for listing the collections.
  * @return array Returns the names of the all the collections in the database as an array
  */
 public function getCollectionNames(array $options = [])
 {
     $includeSystemCollections = false;
     // The includeSystemCollections option is no longer supported in the command
     if (isset($options['includeSystemCollections'])) {
         $includeSystemCollections = $options['includeSystemCollections'];
         unset($options['includeSystemCollections']);
     }
     try {
         $collections = $this->db->listCollections($options);
     } catch (\MongoDB\Driver\Exception\Exception $e) {
         throw ExceptionConverter::toLegacy($e);
     }
     $getCollectionName = function (CollectionInfo $collectionInfo) {
         return $collectionInfo->getName();
     };
     $eligibleCollections = array_filter(iterator_to_array($collections), $this->getSystemCollectionFilterClosure($includeSystemCollections));
     return array_map($getCollectionName, $eligibleCollections);
 }