lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
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]) && isset($dcs[$fieldName][0]) && $dcs[$fieldName][0] != $dcs[$fieldName][1]) {
            throw MongoDBException::shardKeyFieldCannotBeChanged($shardKeyField, $this->class->getName(), $dcs);
        }

        if (!isset($actualDocumentData[$fieldName])) {
            throw MongoDBException::shardKeyFieldMissing($shardKeyField, $this->class->getName());
        }
    }
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]) && isset($dcs[$fieldName][0]) && $dcs[$fieldName][0] != $dcs[$fieldName][1]) {
            throw MongoDBException::shardKeyFieldCannotBeChanged($shardKeyField, $this->class->getName(), $dcs);
        }

        if (!isset($actualDocumentData[$fieldName])) {
            throw MongoDBException::shardKeyFieldMissing($shardKeyField, $this->class->getName());
        }
    }
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 ] ) && isset ( $ dcs [ $ fieldName ] [ 0 ] ) && $ dcs [ $ fieldName ] [ 0 ] != $ dcs [ $ fieldName ] [ 1 ] ) { throw MongoDBException :: shardKeyFieldCannotBeChanged ( $ shardKeyField , $ this -> class -> getName ( ) , $ dcs ) ; } if ( ! isset ( $ actualDocumentData [ $ fieldName ] ) ) { throw MongoDBException :: shardKeyFieldMissing ( $ shardKeyField , $ this -> class -> getName ( ) ) ; } }
If the document is new, ignore shard key field value, otherwise throw an exception.
Also, shard key field should be presented in actual document data.

@param object $document
@param string $shardKeyField
@param array  $actualDocumentData

@throws MongoDBException
If the document is new ignore shard key field value otherwise throw an exception . Also shard key field should be presented in actual document data .