本文整理匯總了PHP中Doctrine\ODM\MongoDB\MongoDBException::shardKeyChange方法的典型用法代碼示例。如果您正苦於以下問題:PHP MongoDBException::shardKeyChange方法的具體用法?PHP MongoDBException::shardKeyChange怎麽用?PHP MongoDBException::shardKeyChange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ODM\MongoDB\MongoDBException
的用法示例。
在下文中一共展示了MongoDBException::shardKeyChange方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getShardKeyQuery
/**
* @param $document
* @return array
* @throws MongoDBException
*/
public function getShardKeyQuery($document)
{
$shardKeysQueryPart = array();
$dcs = $this->uow->getDocumentChangeSet($document);
$data = $this->uow->getDocumentActualData($document);
$md = $this->dm->getMetadataFactory()->getMetadataFor(get_class($document));
$keys = $md->shardKeys;
$fieldMappings = $this->dm->getClassMetadata(get_class($document))->fieldMappings;
foreach ($keys as $key) {
if ($key !== 'id') {
$queryKey = $fieldMappings[$key]['name'];
} else {
$queryKey = '_id';
}
//If the document is new, we can ignore shard key value, otherwise throw exception
$isUpdate = $this->uow->isScheduledForUpdate($document);
if ($isUpdate && isset($dcs[$key]) && $dcs[$key][0] !== null && $dcs[$key][0] != $dcs[$key][1] && (!isset($options['upsert']) || isset($options['upsert']) && $options['upsert'] === true)) {
throw MongoDBException::shardKeyChange($key);
}
if (!isset($data[$key])) {
throw MongoDBException::shardKeyMissing($key);
}
$new = $data[$key];
$mapping = $fieldMappings[$key];
// @Field, @String, @Date, etc.
if (!isset($mapping['association'])) {
if (isset($new) || $mapping['nullable'] === true) {
$shardKeysQueryPart[$queryKey] = is_null($new) ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new);
}
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) {
if (isset($new) || $mapping['nullable'] === true) {
$shardKeysQueryPart[$queryKey] = is_null($new) ? null : $this->pb->prepareReferencedDocumentValue($mapping, $new);
}
// @ReferenceMany
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_MANY) {
// Do nothing right now
}
}
return $shardKeysQueryPart;
}