本文整理汇总了PHP中Doctrine\ODM\MongoDB\MongoDBException::shardKeyMissing方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBException::shardKeyMissing方法的具体用法?PHP MongoDBException::shardKeyMissing怎么用?PHP MongoDBException::shardKeyMissing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\MongoDBException
的用法示例。
在下文中一共展示了MongoDBException::shardKeyMissing方法的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;
}