当前位置: 首页>>代码示例>>PHP>>正文


PHP MongoCollection::save方法代码示例

本文整理汇总了PHP中MongoCollection::save方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::save方法的具体用法?PHP MongoCollection::save怎么用?PHP MongoCollection::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoCollection的用法示例。


在下文中一共展示了MongoCollection::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doWrite

 /**
  * Write a message to the log.
  *
  * @param array $event Event data
  * @return void
  * @throws Zend\Log\Exception\RuntimeException
  */
 protected function doWrite(array $event)
 {
     if (null === $this->mongoCollection) {
         throw new RuntimeException('MongoCollection must be defined');
     }
     $this->mongoCollection->save($event, $this->saveOptions);
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:14,代码来源:MongoDB.php

示例2: save

 public function save($document)
 {
     $data = $this->objectFactory->marshal($document);
     $this->mongoCollection->save($data);
     $this->objectFactory->setId($document, $data['_id']);
     return $this;
 }
开发者ID:dav-m85,项目名称:simple-mongo,代码行数:7,代码来源:Collection.php

示例3: write

 /**
  * Write messages
  *
  * @return mixed|void
  */
 public function write()
 {
     foreach ($this->messages as $message) {
         $message['log'] = $this->format($message);
         $this->collection->save($message);
     }
 }
开发者ID:pagon,项目名称:logger,代码行数:12,代码来源:MongoDB.php

示例4: persist

 /**
  * {@inheritDoc}
  */
 public function persist(Persistable $doc)
 {
     $struc = $this->factory->desegregate($doc);
     if (array_key_exists('id', $struc)) {
         unset($struc['id']);
     }
     if (!is_null($doc->getId())) {
         $struc['_id'] = $doc->getId();
     }
     $this->collection->save($struc);
     $doc->setId($struc['_id']);
 }
开发者ID:trismegiste,项目名称:yuurei,代码行数:15,代码来源:Repository.php

示例5: write

 /**
  * Write Session Data
  *
  * @param string $id
  *   Session Data ID
  *
  * @param string $data
  *   Data to Store
  *
  * @param integer $expires
  *   Expiration Timestamp
  *
  * @return boolean
  *   TRUE on success and FALSE on failure
  */
 public function write($id, $data, $expires)
 {
     if (!empty($_SESSION)) {
         $this->collection->save(array('_id' => $id, 'data' => eval(sprintf('return %s;', preg_replace(array('/\\w+::__set_state\\(/', '/\\)\\)/'), array(NULL, ')'), var_export($_SESSION, TRUE)))), 'serialized' => new \MongoBinData(gzcompress($data)), 'expires' => new \MongoDate(time() + $expires)));
     }
     return TRUE;
 }
开发者ID:nextframework,项目名称:next,代码行数:22,代码来源:Mongo.php

示例6: set

 /**
  * Save data to a the MongoDB collection
  * 
  * @param integer $id
  * @param array $data
  * @param integer $lifetime
  * @param mixed $tags
  * @return boolean
  */
 private function set($id, $data, $lifetime, $tags)
 {
     list($nowMicroseconds, $nowSeconds) = explode(' ', microtime());
     $nowMicroseconds = intval($nowMicroseconds * 1000000);
     //Convert from 'expressed in seconds' to complete microseconds
     return $this->_collection->save(array('_id' => $id, 'd' => $data, 'created_at' => new \MongoDate($nowSeconds, $nowMicroseconds), 'expires_at' => is_numeric($lifetime) && intval($lifetime) !== 0 ? new \MongoDate($nowSeconds + $lifetime, $nowMicroseconds) : null, 't' => $tags, 'hits' => 0));
 }
开发者ID:TerranetMD,项目名称:zf-cache-backend,代码行数:16,代码来源:Mongo.php

示例7: 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;
     }
 }
开发者ID:nourdine,项目名称:session,代码行数:24,代码来源:MongoSessionHandler.php

示例8: doSave

 /**
  * Execute the save query.
  *
  * @see Collection::save()
  * @param array $a
  * @param array $options
  * @return array|boolean
  */
 protected function doSave(array &$a, 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->save($a, $options);
 }
开发者ID:pmnyaga,项目名称:mongodb,代码行数:15,代码来源:Collection.php

示例9: save

 /**
  * Will add or update an existing object with a matching _id
  * 
  * @param type $value object to save 
  */
 public function save($value)
 {
     ValidatorsUtil::isNullOrEmpty($this->_mongoCollection, "Mongo collection isn't valid, have you set a collection?");
     ValidatorsUtil::isNull($value, "Must have a valid object to insert in collection");
     $this->_mongoCollection->save($value);
     $this->_count = 0;
 }
开发者ID:retrogamer4ever,项目名称:php-tools,代码行数:12,代码来源:MongoConnection.php

示例10: set

 /**
  * @param int $id
  * @param array $data
  * @param int $lifetime
  * @param mixed $tags
  * @return boolean
  */
 public function set($id, $data, $lifetime, $tags)
 {
     $now = time();
     // set the lifetime to 1 year if it is null
     if (!$lifetime) {
         $lifetime = 86400 * 365;
     }
     return $this->_collection->save(['_id' => $id, 'd' => $data, 'created_at' => $now, 'l' => $lifetime, 'expire' => $now + $lifetime, 't' => $tags]);
 }
开发者ID:solverat,项目名称:pimcore,代码行数:16,代码来源:Mongodb.php

示例11: save

 /**
  * Saving record to the database
  * @param boolean $validate Validate record before saving
  * @param boolean $throw Throw an expcetion if an error occured
  * @return boolean Operation success mark
  * @throws \MongoAR\Exception If an error occured and $throw is set to TRUE
  * @since 0.1
  */
 public function save($validate = true, $throw = false)
 {
     if ($this->id) {
         $this->document['_id'] = $this->id;
     }
     $response = $this->table->save($this->document);
     $this->fetchId($this->document);
     return $this->checkResponse($response, $throw);
 }
开发者ID:tatarko,项目名称:mongoar,代码行数:17,代码来源:ActiveRecord.php

示例12: storeData

 /**
  * {@inheritdoc}
  */
 public function storeData($key, $data, $expiration)
 {
     if ($this->collection instanceof \MongoDB\Collection) {
         $id = self::mapKey($key);
         try {
             $this->collection->replaceOne(['_id' => $id], ['_id' => $id, 'data' => serialize($data), 'expiration' => $expiration], ['upsert' => true]);
         } catch (\MongoDB\Driver\Exception\BulkWriteException $ignored) {
             // As of right now, BulkWriteException can be thrown by replaceOne in high-throughput environments where race conditions can occur
         }
     } else {
         try {
             $this->collection->save(['_id' => self::mapKey($key), 'data' => serialize($data), 'expiration' => $expiration]);
         } catch (\MongoDuplicateKeyException $ignored) {
             // Because it's Mongo, we might have had this problem because of a cache stampede
         }
     }
     return true;
 }
开发者ID:Fiskie,项目名称:mongostash,代码行数:21,代码来源:MongoDB.php

示例13: save

 /**
  * Write a profile to the mongo database
  *
  * @param array $profile Profiler Collected Data
  * @return void
  * @throws Exception\RuntimeException
  */
 public function save(array $profile)
 {
     if (null === $this->mongoCollection) {
         throw new Exception\RuntimeException('MongoCollection must be defined');
     }
     if ($this->hostname !== 'all') {
         $profile['report']['hostname'] = $this->hostname;
     }
     $this->mongoCollection->save($profile, $this->saveOptions);
 }
开发者ID:antoinebon,项目名称:zf2,代码行数:17,代码来源:ProfileMapper.php

示例14: doWrite

 /**
  * Write a message to the log.
  *
  * @param array $event Event data
  * @return void
  * @throws Zend\Log\Exception\RuntimeException
  */
 protected function doWrite(array $event)
 {
     if (null === $this->mongoCollection) {
         throw new RuntimeException('MongoCollection must be defined');
     }
     if (isset($event['timestamp']) && $event['timestamp'] instanceof DateTime) {
         $event['timestamp'] = new MongoDate($event['timestamp']->getTimestamp());
     }
     $this->mongoCollection->save($event, $this->saveOptions);
 }
开发者ID:raZ3l,项目名称:zf2,代码行数:17,代码来源:MongoDB.php

示例15: testGroup2

 public function testGroup2()
 {
     $this->object->save(array("a" => 2));
     $this->object->save(array("b" => 5));
     $this->object->save(array("a" => 1));
     $keys = array();
     $initial = array("count" => 0);
     $reduce = "function (obj, prev) { prev.count++; }";
     $g = $this->object->group($keys, $initial, $reduce);
     $this->assertEquals(3, $g['count']);
 }
开发者ID:salathe,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoCollectionTest.php


注:本文中的MongoCollection::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。