failedToEnableSharding() public static method

public static failedToEnableSharding ( string $dbName, string $errorMessage ) : MongoDBException
$dbName string
$errorMessage string
return MongoDBException
Ejemplo n.º 1
0
 /**
  * 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']);
     }
 }
Ejemplo n.º 2
0
 /**
  * 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']);
 }