本文整理汇总了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']);
}
示例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) {
}
}
示例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());
}
}
示例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++;
}
示例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']);
}
示例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']);
}
}
示例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;
}
示例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));
}
示例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'));
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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) {}
}