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


PHP MongoCollection::insert方法代码示例

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


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

示例1: doLog

 /**
  * Logs a message.
  *
  * @param string $message   Message
  * @param string $priority  Message priority
  */
 protected function doLog($message, $priority)
 {
     $document = array('message' => $message, 'priority' => $priority);
     $event = new sfEvent($this, 'mongodblog.pre_insert');
     $this->dispatcher->filter($event, $document);
     $this->collection->insert($event->getReturnValue(), $this->options['save']);
 }
开发者ID:havvg,项目名称:sfMongoDBLoggerPlugin,代码行数:13,代码来源:sfMongoDBLogger.class.php

示例2: _log

 /**
  */
 protected function _log($action, $message_id, $recipient, $success)
 {
     try {
         $this->_db->insert(array(self::ACTION => $action, self::MESSAGEID => $message_id, self::RECIPIENT => $recipient, self::SUCCESS => intval($success), self::TS => time(), self::WHO => $GLOBALS['registry']->getAuth()));
     } catch (MongoException $e) {
     }
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:9,代码来源:Mongo.php

示例3: cache

 /**
  * {@inheritDoc}
  */
 public function cache(BatchGeocoded $geocoded)
 {
     try {
         $this->collection->insert(array_merge(array('id' => $this->getKey($geocoded->getProviderName(), $geocoded->getQuery())), $this->normalize($geocoded)));
     } catch (\Exception $e) {
         throw new RuntimeException($e->getMessage());
     }
 }
开发者ID:vanslambrouckd,项目名称:geotools,代码行数:11,代码来源:MongoDB.php

示例4: addDocument

 /**
  * Add a new Document to the DocumentStore
  * @param Document $document Document to add
  */
 public function addDocument(Document $document)
 {
     $id = new \MongoId();
     $document->_id = $id;
     $this->documents->insert($document);
     unset($document->_id);
     $this->size++;
 }
开发者ID:markusos,项目名称:simple-search,代码行数:12,代码来源:MongoDBDocumentStore.php

示例5: testSkipCacheAggregate

 public function testSkipCacheAggregate()
 {
     $result = $this->collection->aggregate([['$group' => ['_id' => 'foo', 'sum' => ['$sum' => '$foo']]]]);
     $this->assertEquals(4, $result['result'][0]['sum']);
     $this->collection->insert(['foo' => 3]);
     $result = $this->collection->aggregate([['$group' => ['_id' => 'foo', 'sum' => ['$sum' => '$foo']]]], ['cache' => false]);
     $this->assertEquals(7, $result['result'][0]['sum']);
 }
开发者ID:nicklasos,项目名称:MongoCache,代码行数:8,代码来源:MongoCollectionTest.php

示例6: push

 /**
  * @see QueueInterface::push()
  */
 public function push(TaskInterface $task)
 {
     $eta = $task->getEta() ?: new \DateTime();
     $data = array('eta' => new \MongoDate($eta->getTimestamp()), 'task' => $this->serializer->serialize($task));
     $result = $this->collection->insert($data, array('safe' => true));
     if (!$result['ok']) {
         throw new \RuntimeException($result['errmsg']);
     }
 }
开发者ID:rybakit,项目名称:taskqueue,代码行数:12,代码来源:MongoDBQueue.php

示例7: save

 public function save(Contact $contact)
 {
     try {
         $this->contactsManagerCollection->insert(array('name' => $contact->getName(), 'email' => $contact->getEmail(), 'photo' => $contact->getPhoto()), array('safe' => true));
         return true;
     } catch (MongoCursorException $e) {
         //log
     }
     return false;
 }
开发者ID:lga37,项目名称:contacts,代码行数:10,代码来源:ContactMongoStorage.php

示例8: testFields

 public function testFields()
 {
     $this->object->insert(array("x" => array(1, 2, 3, 4, 5)));
     $results = $this->object->find(array(), array("x" => array('$slice' => 3)))->getNext();
     $r = $results['x'];
     $this->assertTrue(array_key_exists(0, $r));
     $this->assertTrue(array_key_exists(1, $r));
     $this->assertTrue(array_key_exists(2, $r));
     $this->assertFalse(array_key_exists(3, $r));
     $this->assertFalse(array_key_exists(4, $r));
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoCollectionTest2.php

示例9: setUp

 protected function setUp()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped('Mongo is not installed');
     }
     $mongo = new \MongoClient();
     $this->module = new MongoDb();
     $this->module->_setConfig($this->mongoConfig);
     $this->module->_initialize();
     $this->db = $mongo->selectDB('test');
     $this->userCollection = $this->db->createCollection('users');
     $this->userCollection->insert(array('id' => 1, 'email' => 'miles@davis.com'));
 }
开发者ID:Eli-TW,项目名称:Codeception,代码行数:13,代码来源:MongoDbTest.php

示例10: add

 /**
  * @param $firstname
  * @param $lastname
  * @param $login
  * @param $password
  */
 public function add($firstname, $lastname, $login, $password, $email)
 {
     //TODO инкапсулировать в метод и обработать данные понадежнее
     //убираем лишние пробелы
     $firstname = trim($firstname);
     $lastname = trim($lastname);
     $login = trim($login);
     $password = trim($password);
     $email = trim($email);
     //формируем документ
     $document = ["firstname" => $firstname, "lastname" => $lastname, "login" => $login, "password" => $password, "email" => $email];
     //вставляем в коллекцию
     UsersCollection::$collection->insert($document);
 }
开发者ID:ChupinDO,项目名称:blog_mongodb,代码行数:20,代码来源:UsersCollection.php

示例11: append

 /**
  * Appends a new event to the mongo database.
  * 
  * @throws LoggerException If the pattern conversion or the INSERT statement fails.
  */
 public function append(LoggerLoggingEvent $event)
 {
     if ($this->canAppend == true && $this->collection != null) {
         $document = $this->format($event);
         $this->collection->insert($document);
     }
 }
开发者ID:alexandreannic,项目名称:android-holo-colors,代码行数:12,代码来源:LoggerAppenderMongoDB.php

示例12: log

 /**
  * Logs a message to Mongodb
  * @param mixed $message The object to log
  * @param int $level The level of the log event
  */
 protected function log($message, $level = self::LOG_LEVEL_ERROR)
 {
     if ($message instanceof \Exception) {
         $level = self::LOG_LEVEL_EXCEPTION;
         $slog = sprintf('%s in %s [%d]', $message->getMessage(), $message->getFile(), $message->getLine());
         $trace = array();
         $stack = array_slice($message->getTrace(), 1);
         foreach ($stack as $t) {
             $trace[] = sprintf('%sin %s %s%s%s() [%d]', "\t", $t['file'], $t['class'], $t['type'] == '' ? '->' : $t['type'], $t['function'], $t['line']);
         }
         $slog .= PHP_EOL;
         $slog .= implode(PHP_EOL, $trace);
         $message = $slog;
     }
     $record = array('date' => new \MongoDate(), 'level' => static::LogLevel($level));
     if (is_scalar($message)) {
         $record['message'] = $message;
     } else {
         if (is_callable($this->serializer)) {
             $record['message'] = call_user_func_array($this->server, array($message));
         } else {
             $record['message'] = print_r($message, true);
         }
     }
     $this->collection->insert($record);
 }
开发者ID:sesser,项目名称:slogger,代码行数:31,代码来源:Mongodb.php

示例13: insert

 /**
  * Inserts a new object into the collection
  * 
  * @param Object $value lets you add an object to database
  */
 public function insert($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->insert($value, true);
     $this->_count = 0;
 }
开发者ID:retrogamer4ever,项目名称:php-tools,代码行数:12,代码来源:MongoConnection.php

示例14: set

 /**
  * Sets an item in the cache given its key and data value.
  *
  * @param string $key The key to use.
  * @param mixed $data The data to set.
  * @return bool True if the operation was a success false otherwise.
  */
 public function set($key, $data)
 {
     if (!is_array($key)) {
         $record = array('key' => $key);
     } else {
         $record = $key;
     }
     $record['data'] = serialize($data);
     $options = array('upsert' => true);
     if ($this->legacymongo) {
         $options['safe'] = $this->usesafe;
     } else {
         $options['w'] = $this->usesafe ? 1 : 0;
     }
     $this->delete($key);
     $result = $this->collection->insert($record, $options);
     if ($result === true) {
         // Safe mode is off.
         return true;
     } else {
         if (is_array($result)) {
             if (empty($result['ok']) || isset($result['err'])) {
                 return false;
             }
             return true;
         }
     }
     // Who knows?
     return false;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:37,代码来源:lib.php

示例15: testTags

 public function testTags() {
     // does not throw in 1.8
     try {
         $this->object->insert(array("x"=>1), array("safe" => "foo", "wtimeout" => 1000));
     }
     catch (MongoCursorException $e) {}
 }
开发者ID:neurodrone,项目名称:mongo-php-driver,代码行数:7,代码来源:MongoCollectionTest.php


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