Doctrine\ODM\MongoDB\DocumentManager::getDocumentDatabase PHP Method

getDocumentDatabase() public method

Returns the MongoDB instance for a class.
public getDocumentDatabase ( string $className ) : Doctrine\MongoDB\Database
$className string The class name.
return Doctrine\MongoDB\Database
    public function getDocumentDatabase($className)
    {
        $className = ltrim($className, '\\');
        if (isset($this->documentDatabases[$className])) {
            return $this->documentDatabases[$className];
        }
        $metadata = $this->metadataFactory->getMetadataFor($className);
        $db = $metadata->getDatabase();
        $db = $db ?: $this->config->getDefaultDB();
        $db = $db ?: 'doctrine';
        $this->documentDatabases[$className] = $this->connection->selectDatabase($db);
        return $this->documentDatabases[$className];
    }

Usage Example

Example #1
0
 protected function skipTestIfNotSharded($className)
 {
     $result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true]);
     if (!$result['ok']) {
         $this->markTestSkipped('Could not check whether server supports sharding');
     }
     if (!array_key_exists('shardCollection', $result['commands'])) {
         $this->markTestSkipped('Test skipped because server does not support sharding');
     }
 }
All Usage Examples Of Doctrine\ODM\MongoDB\DocumentManager::getDocumentDatabase