public function open()
    {
        if ($this->manager === null) {
            if (empty($this->dsn)) {
                throw new InvalidConfigException($this->className() . '::dsn cannot be empty.');
            }
            $token = 'Opening MongoDB connection: ' . $this->dsn;
            try {
                Yii::trace($token, __METHOD__);
                Yii::beginProfile($token, __METHOD__);
                $options = $this->options;

                $this->manager = new Manager($this->dsn, $options, $this->driverOptions);
                $this->manager->selectServer($this->manager->getReadPreference());

                $this->initConnection();
                Yii::endProfile($token, __METHOD__);
            } catch (\Exception $e) {
                Yii::endProfile($token, __METHOD__);
                throw new Exception($e->getMessage(), (int) $e->getCode(), $e);
            }

            $this->typeMap = array_merge(
                $this->typeMap,
                [
                    'root' => 'array',
                    'document' => 'array'
                ]
            );
        }
    }
public function open()
    {
        if ($this->manager === null) {
            if (empty($this->dsn)) {
                throw new InvalidConfigException($this->className() . '::dsn cannot be empty.');
            }
            $token = 'Opening MongoDB connection: ' . $this->dsn;
            try {
                Yii::trace($token, __METHOD__);
                Yii::beginProfile($token, __METHOD__);
                $options = $this->options;

                $this->manager = new Manager($this->dsn, $options, $this->driverOptions);
                $this->manager->selectServer($this->manager->getReadPreference());

                $this->initConnection();
                Yii::endProfile($token, __METHOD__);
            } catch (\Exception $e) {
                Yii::endProfile($token, __METHOD__);
                throw new Exception($e->getMessage(), (int) $e->getCode(), $e);
            }

            $this->typeMap = array_merge(
                $this->typeMap,
                [
                    'root' => 'array',
                    'document' => 'array'
                ]
            );
        }
    }
public function open ( ) { if ( $ this -> manager === null ) { if ( empty ( $ this -> dsn ) ) { throw new InvalidConfigException ( $ this -> className ( ) . '::dsn cannot be empty.' ) ; } $ token = 'Opening MongoDB connection: ' . $ this -> dsn ; try { Yii :: trace ( $ token , __METHOD__ ) ; Yii :: beginProfile ( $ token , __METHOD__ ) ; $ options = $ this -> options ; $ this -> manager = new Manager ( $ this -> dsn , $ options , $ this -> driverOptions ) ; $ this -> manager -> selectServer ( $ this -> manager -> getReadPreference ( ) ) ; $ this -> initConnection ( ) ; Yii :: endProfile ( $ token , __METHOD__ ) ; } catch ( \ Exception $ e ) { Yii :: endProfile ( $ token , __METHOD__ ) ; throw new Exception ( $ e -> getMessage ( ) , ( int ) $ e -> getCode ( ) , $ e ) ; } $ this -> typeMap = array_merge ( $ this -> typeMap , [ 'root' => 'array' , 'document' => 'array' ] ) ; } }
Establishes a Mongo connection.
It does nothing if a MongoDB connection has already been established.
@throws Exception if connection fails
Establishes a Mongo connection . It does nothing if a MongoDB connection has already been established .