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

shardKeyFieldCannotBeChanged() public static method

public static shardKeyFieldCannotBeChanged ( string $field, string $className ) : MongoDBException
$field string
$className string
return MongoDBException
    public static function shardKeyFieldCannotBeChanged($field, $className)
    {
        return new self(sprintf('Shard key field "%s" in class "%s" cannot be changed.', $field, $className));
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * If the document is new, ignore shard key field value, otherwise throw an exception.
  * Also, shard key field should be present in actual document data.
  *
  * @param object $document
  * @param string $shardKeyField
  * @param array  $actualDocumentData
  *
  * @throws MongoDBException
  */
 private function guardMissingShardKey($document, $shardKeyField, $actualDocumentData)
 {
     $dcs = $this->uow->getDocumentChangeSet($document);
     $isUpdate = $this->uow->isScheduledForUpdate($document);
     $fieldMapping = $this->class->getFieldMappingByDbFieldName($shardKeyField);
     $fieldName = $fieldMapping['fieldName'];
     if ($isUpdate && isset($dcs[$fieldName]) && $dcs[$fieldName][0] != $dcs[$fieldName][1]) {
         throw MongoDBException::shardKeyFieldCannotBeChanged($shardKeyField, $this->class->getName());
     }
     if (!isset($actualDocumentData[$fieldName])) {
         throw MongoDBException::shardKeyFieldMissing($shardKeyField, $this->class->getName());
     }
 }