本文整理汇总了PHP中MongoCollection::update方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::update方法的具体用法?PHP MongoCollection::update怎么用?PHP MongoCollection::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Zapisuję dokonane zmiany w bazie
*
* @return void
*/
public function save()
{
$aMods = [];
// dla modelu z modułami
if ($this->aModules !== null) {
// obsługa modułów
foreach ($this->aModules as $mModule) {
if (!$mModule instanceof Module) {
continue;
}
$aChanges = $mModule->beforeSave();
$aMods[] = $mModule;
if (!empty($aChanges)) {
$this->mergeChanges($aChanges);
}
}
}
$aChanges = $this->getChanges();
// zapisuję jeśli się coś zmieniło
if (!empty($aChanges)) {
$this->oCollection->update(['_id' => $this->getId(true)], $this->getChanges());
$this->clearChanges();
// post save
foreach ($aMods as $oModule) {
$oModule->afterSave();
}
}
}
示例2: set
/**
* Store the api $response as the cached result of the api $request.
*
* @param RequestInterface $request The request for which the response will be cached.
* @param ResponseInterface $response The reponse to cache.
* @param integer $timeToLive The time in seconds that the cache should live.
*
* @return void
*
* @throws \InvalidArgumentException Throw if $timeToLive is not an integer between 0 and 86400.
*/
public function set(RequestInterface $request, ResponseInterface $response, $timeToLive = null)
{
$timeToLive = self::ensureTTL($timeToLive ?: $this->getDefaultTTL());
$id = $request->getUrl();
$cache = ['_id' => $id, 'httpCode' => $response->getHttpCode(), 'body' => $response->getBody(), 'headers' => $response->getHeaders(), 'expires' => new \MongoDate(time() + $timeToLive)];
$this->collection->update(['_id' => $id], $cache, ['upsert' => true]);
}
示例3: update
public function update(Kwf_Model_Row_Interface $row, $rowData)
{
$ret = $this->_collection->update(array('_id' => $row->_id), $rowData, array('safe' => true, 'multiple' => false));
if (!$ret || $ret['ok'] != 1) {
throw new Kwf_Exception("update failed");
}
}
示例4: addDocument
public function addDocument(Document $document)
{
$uniqueTokens = array_unique($document->tokens);
foreach ($uniqueTokens as $token) {
$this->index->update(["token" => $token], ['$push' => ["documents" => $document->id]], ["upsert" => true]);
}
}
示例5: updateObject
public function updateObject($object, ChangeSet $changeSet)
{
$data = $this->prepareUpdateChangeSet($object, $changeSet);
unset($data['_id']);
$this->mongoCollection->update($this->getObjectIdentifier($object), array('$set' => $data));
return $data;
}
示例6: add
/**
*/
public function add($tokenID)
{
$data = array(self::ADDRESS => $this->_encodeRemoteAddress(), self::TID => $tokenID);
try {
$this->_db->update($data, array('$set' => array_merge($data, array(self::TIMESTAMP => time()))), array('upsert' => true));
} catch (MongoException $e) {
throw new Horde_Token_Exception($e);
}
}
示例7: set
/**
* {@inheritdoc }
*/
public function set($key, $value, $ttl = null)
{
$tKey = $this->getKey($key);
$tValue = $this->pack($value);
if (!$ttl) {
$ttl = $this->ttl;
}
$item = array('_id' => $tKey, 'value' => $tValue, 'ttl' => $this->getTtl($ttl));
$this->collection->update(array('_id' => $tKey), $item, array('upsert' => true));
}
示例8: write
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
$data = unserialize($data);
// we don't save empty sessions
if (isset($new_data['_sf2_attributes']) && count($new_data['_sf2_attributes']) === 0) {
return true;
}
$this->collection->update(['_id' => $this->encodeSessionId($sessionId)], ['$set' => ['data' => $data, 'expireat' => new \MongoDate(time() + $this->ttl)]], ['upsert' => true, 'multiple' => false]);
return true;
}
示例9: update
public function update($entity, $options = ['multiple' => true])
{
$id = null;
foreach (['id', '_id'] as $key) {
if (isset($entity[$key])) {
$id = (string) $entity[$key];
unset($entity[$key]);
}
}
$this->collection->update(['_id' => new MongoId($id)], ['$set' => $entity], $options);
}
示例10: saveData
/**
* @param string $key Unique key for data that is results of action
* @param array $data Results of actions
* @return bool
*/
public function saveData($key, array $data)
{
//@todo Это чтобы гарантировать наличие ключа. Потом возможно заменим это схемой документов
$data['key'] = $key;
$status = $this->dataCollection->update(['key' => $key], $data, ['upsert' => true]);
if ($status['ok'] != 1) {
$this->logger->error('Node data can not save', ['nodeName' => $this->name, 'dataKey' => $key, 'mongoStatus' => $status]);
return false;
}
$this->logger->info('Node data saved', ['nodeName' => $this->name, 'dataKey' => $key]);
return true;
}
示例11: doUpdate
/**
* Execute the update query.
*
* @see Collection::update()
* @param array $query
* @param array $newObj
* @param array $options
* @return array|boolean
*/
protected function doUpdate(array $query, array $newObj, array $options)
{
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
$options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
$options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
return $this->mongoCollection->update($query, $newObj, $options);
}
示例12: save
/**
* Save current object to MongoDB
*
* @param boolean $refresh Should refresh the object fields values?
* @return boolean
*/
function save($refresh = false)
{
if (!$this->_collection) {
import("@.RMongoException");
throw new RMongoException("Object is not in any collection, please use setCollection() to method to set a collection.");
}
$bool = true;
if ($this->_id) {
//if exists
if (!empty($this->_operations)) {
$bool = $this->_collection->update(array("_id" => $this->_id), $this->_operations, array("upsert" => false, "multiple" => false));
if ($refresh) {
$bool = $this->refresh();
}
}
} else {
$bool = $this->_collection->insert($this->_attrs, true);
if ($bool) {
$this->_id = $this->_attrs["_id"];
import("@.RMongo");
RMongo::setLastInsertId($this->_id->__toString());
}
}
$this->_operations = array();
return $bool;
}
示例13: write
/**
* This writes to memory.
* After returning PHP will invoke SessionHandler::close.
*
* @param string $sessionId
* @param string $data Serialized shit
* @return boolean
*/
public function write($sessionId, $data)
{
$query = array("session-id" => $sessionId);
$toSave = array_merge($query, array("data" => $data, "time" => time()));
try {
$el = $this->collection->findOne($query);
if ($el === null) {
$result = $this->collection->save($toSave);
} else {
$result = $this->collection->update($query, $toSave);
}
return $result["ok"] == 1;
} catch (MongoCursorException $ex) {
return false;
}
}
示例14: write
/**
* Write Session - commit data to resource
*
* @param string $id
* @param mixed $data
*/
public function write($id, $data)
{
try {
if (empty($_SESSION)) {
$this->destroy($id);
return;
}
$exists = isset($this->_sessionHashes[$id]);
$modified = $exists && $this->_sessionHashes[$id] !== md5($data);
if (!$exists || $modified) {
$filter = array('_id' => $id);
$options = array('upsert' => true, 'multiple' => false);
$update = array('data' => $data, 'metadata.created' => new MongoDate(time()), 'rawData' => $_SESSION);
if (!$exists) {
$update['metadata.expire'] = new MongoDate(time() + $this->_maxLifeTime);
}
\App::cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('session'));
$result = $this->_collection->update($filter, array('$set' => $update), $options);
if ($result['ok'] == 1) {
return true;
}
} else {
return true;
}
} catch (Exception $e) {
\App::log()->crit($e);
}
return false;
}
示例15: doUpdate
protected function doUpdate($query, array $newObj, array $options)
{
if (is_scalar($query)) {
$query = array('_id' => $query);
}
return $this->mongoCollection->update($query, $newObj, $options);
}