public function connect() {
        if ($this->isConnected()) {
            return true;
        }

        if (!$this->isEnabled()) {
            throw new MissingDriverException('mongodb driver extension is not enabled');
        }

        $options = [];

        if ($db = $this->getDatabase()) {
            $options['db'] = $db;
        }

        if ($user = $this->getUser()) {
            $options['username'] = $user;
        }

        if ($pass = $this->getPassword()) {
            $options['password'] = $pass;
        }

        if ($rSet = $this->getConfig('replicaSet')) {
            if (!$this->getConfig('servers')) {
                throw new MissingServersException('A list of servers is required for replica set functionality');
            }

            $options['replicaSet'] = $rSet;
        }

        $connection = new MongoClient($this->getServer(), $options + $this->getConfig('flags'));

        $this->_connections[$this->getContext()] = $connection;

        return $connection->connected;
    }