Doctrine\MongoDB\Connection::isConnected PHP Method

isConnected() public method

Checks whether the connection is initialized and connected.
public isConnected ( ) : boolean
return boolean
    public function isConnected()
    {
        if (!($this->mongoClient instanceof \MongoClient || $this->mongoClient instanceof \Mongo)) {
            return false;
        }
        return count($this->mongoClient->getHosts()) > 0;
    }

Usage Example

 /**
  * Return whether this datasource is connected or not to the persistent storage server
  *
  * @return boolean
  */
 public function isConnected()
 {
     return $this->connection->isConnected();
 }