Doctrine\ODM\MongoDB\MongoDBException::failedToEnsureDocumentSharding PHP Method

failedToEnsureDocumentSharding() public static method

public static failedToEnsureDocumentSharding ( string $className, string $errorMessage ) : MongoDBException
$className string
$errorMessage string
return MongoDBException
    public static function failedToEnsureDocumentSharding($className, $errorMessage)
    {
        return new self(sprintf('Failed to ensure sharding for document "%s". Error from MongoDB: %s', $className, $errorMessage));
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Ensure sharding for collection by document name.
  *
  * @param string $documentName
  * @param array  $indexOptions Options for `ensureIndex` command. It's performed on an existing collections.
  *
  * @throws MongoDBException
  */
 public function ensureDocumentSharding($documentName, array $indexOptions = array())
 {
     $class = $this->dm->getClassMetadata($documentName);
     if (!$class->isSharded()) {
         return;
     }
     $this->enableShardingForDbByDocumentName($documentName);
     do {
         $result = $this->runShardCollectionCommand($documentName);
         $done = true;
         $try = 0;
         if ($result['ok'] != 1 && isset($result['proposedKey'])) {
             $this->dm->getDocumentCollection($documentName)->ensureIndex($result['proposedKey'], $indexOptions);
             $done = false;
             $try++;
         }
     } while (!$done && $try < 2);
     if ($result['ok'] != 1 && $result['errmsg'] !== 'already sharded') {
         throw MongoDBException::failedToEnsureDocumentSharding($documentName, $result['errmsg']);
     }
 }
All Usage Examples Of Doctrine\ODM\MongoDB\MongoDBException::failedToEnsureDocumentSharding