public static failedToEnableSharding ( string $dbName, string $errorMessage ) : |
||
$dbName | string | |
$errorMessage | string | |
Résultat |
/** * Enable sharding for database which contains documents with given name. * * @param string $documentName * * @throws MongoDBException */ public function enableShardingForDbByDocumentName($documentName) { $dbName = $this->dm->getDocumentDatabase($documentName)->getName(); $adminDb = $this->dm->getConnection()->selectDatabase('admin'); $result = $adminDb->command(array('enableSharding' => $dbName)); if ($result['ok'] != 1 && $result['errmsg'] !== 'already enabled') { throw MongoDBException::failedToEnableSharding($dbName, $result['errmsg']); } }
/** * Enable sharding for database which contains documents with given name. * * @param string $documentName * * @throws MongoDBException */ public function enableShardingForDbByDocumentName($documentName) { $dbName = $this->dm->getDocumentDatabase($documentName)->getName(); $adminDb = $this->dm->getConnection()->selectDatabase('admin'); $result = $adminDb->command(array('enableSharding' => $dbName)); // Error code is only available with MongoDB 3.2. MongoDB 3.0 only returns a message // Thus, check code if it exists and fall back on error message if ($result['ok'] == 1 || isset($result['code']) && $result['code'] == 23 || $result['errmsg'] == 'already enabled') { return; } throw MongoDBException::failedToEnableSharding($dbName, $result['errmsg']); }