A file collection object is usually created by calling [[Database::getFileCollection()]] or [[Connection::getFileCollection()]]. File collection inherits all interface from regular [[\yii\mongo\Collection]], adding methods to store files.
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\mongodb\Collection
Example #1
0
 /**
  * Fetches associated file collection from stream options.
  * @return Collection file collection instance.
  * @throws InvalidConfigException on invalid stream options.
  */
 private function fetchCollection()
 {
     $contextOptions = $this->getContextOptions();
     if (isset($contextOptions[$this->protocol]['collection'])) {
         $collection = $contextOptions[$this->protocol]['collection'];
         if ($collection instanceof Collection) {
             throw new InvalidConfigException('"collection" context option should be an instance of "' . Collection::className() . '"');
         }
         return $collection;
     }
     if (isset($contextOptions[$this->protocol]['db'])) {
         $connection = $contextOptions[$this->protocol]['db'];
     } else {
         $connection = 'mongodb';
     }
     /* @var $connection Connection */
     $connection = Instance::ensure($connection, Connection::className());
     list($databaseName, $collectionPrefix) = explode('.', $this->namespace, 2);
     return $connection->getDatabase($databaseName)->getFileCollection($collectionPrefix);
 }