/**
  * Create every requested collection index.
  *
  * @throws \MongoException
  */
 public function createIndexes()
 {
     foreach ($this->getCollections() as $collection) {
         if (empty($indexes = $collection->getIndexes())) {
             continue;
         }
         //We can safely create odm Collection here, as we not going to use functionality requires
         //finalized schema
         $odmCollection = $this->odm->db($collection->getDatabase())->odmCollection($collection->getName());
         foreach ($indexes as $index) {
             $options = [];
             if (isset($index[Document::INDEX_OPTIONS])) {
                 $options = $index[Document::INDEX_OPTIONS];
                 unset($index[Document::INDEX_OPTIONS]);
             }
             $odmCollection->ensureIndex($index, $options);
         }
     }
 }
Exemple #2
0
 /**
  * MongoDatabase instance.
  *
  * @return MongoDatabase
  */
 protected function mongoDatabase()
 {
     return $this->odm->db($this->database);
 }
Exemple #3
0
 /**
  * @param FilesInterface $files
  * @param ODM            $odm
  * @param array          $options
  */
 public function __construct(FilesInterface $files, ODM $odm, array $options)
 {
     parent::__construct($files, $options);
     $this->database = $odm->db($this->options['database']);
 }