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


PHP MongoCollection::getCollection方法代码示例

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


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

示例1: execute

 /**
  * Executes a batch of write operations
  *
  * @see http://php.net/manual/en/mongowritebatch.execute.php
  * @param array $writeOptions
  * @return array
  */
 public final function execute(array $writeOptions = [])
 {
     $writeOptions += $this->writeOptions;
     if (!count($this->items)) {
         return ['ok' => true];
     }
     if (isset($writeOptions['j'])) {
         trigger_error('j parameter is not supported', E_WARNING);
     }
     if (isset($writeOptions['fsync'])) {
         trigger_error('fsync parameter is not supported', E_WARNING);
     }
     $options['writeConcern'] = $this->createWriteConcernFromArray($writeOptions);
     if (isset($writeOptions['ordered'])) {
         $options['ordered'] = $writeOptions['ordered'];
     }
     $collection = $this->collection->getCollection();
     try {
         $result = $collection->BulkWrite($this->items, $options);
         $ok = 1.0;
     } catch (\MongoDB\Driver\Exception\BulkWriteException $e) {
         $result = $e->getWriteResult();
         $ok = 0.0;
     }
     if ($ok === 1.0) {
         $this->items = [];
     }
     return ['ok' => $ok, 'nInserted' => $result->getInsertedCount(), 'nMatched' => $result->getMatchedCount(), 'nModified' => $result->getModifiedCount(), 'nUpserted' => $result->getUpsertedCount(), 'nRemoved' => $result->getDeletedCount()];
 }
开发者ID:lewnie,项目名称:mongo-php-adapter,代码行数:36,代码来源:MongoWriteBatch.php

示例2: __construct

 /**
  * Model contructor
  * 
  * Build the model
  */
 public function __construct($doc, $collection)
 {
     // New document
     if ($doc === null) {
         $doc = array();
     }
     // Validate doc
     if (!is_array($doc)) {
         throw new \RuntimeException('$data must be array.');
     }
     if (!isset($doc['_id']) || $doc['_id'] instanceof \MongoId) {
         $this->_doc = $doc;
     } else {
         foreach ($doc as $k => $v) {
             $this->_setter($k, $v);
         }
     }
     // Validate collection
     $this->_collection = $collection;
     if ($collection instanceof \MongoCollection) {
         $collection = new MongoCollection($collection);
         $this->_collection = $collection->getCollection();
     } else {
         if ($collection instanceof Adapters\MongoCollection) {
             $this->_collection = $collection->getCollection();
         } else {
             if (!$collection instanceof Collection) {
                 throw new \RuntimeException('$collection must be an instance of Modomo\\Collection or Modomo\\Adapters\\MongoCollection or MongoCollection');
             }
         }
     }
     // New model
     $this->_new = true;
     if (isset($doc['_id']) && $doc['_id'] instanceof \MongoId) {
         $this->_new = false;
         $this->_collection->triggerEvent('onCreateNew', $this);
     } else {
         $this->_collection->triggerEvent('onCreate', $this);
     }
 }
开发者ID:jrschumacher,项目名称:modomo,代码行数:45,代码来源:Document.php

示例3: execute

 /**
  * Executes a batch of write operations
  *
  * @see http://php.net/manual/en/mongowritebatch.execute.php
  * @param array $writeOptions
  * @return array
  */
 public final function execute(array $writeOptions = [])
 {
     $writeOptions += $this->writeOptions;
     if (!count($this->items)) {
         return ['ok' => true];
     }
     if (isset($writeOptions['j'])) {
         trigger_error('j parameter is not supported', E_WARNING);
     }
     if (isset($writeOptions['fsync'])) {
         trigger_error('fsync parameter is not supported', E_WARNING);
     }
     $options['writeConcern'] = $this->createWriteConcernFromArray($writeOptions);
     if (isset($writeOptions['ordered'])) {
         $options['ordered'] = $writeOptions['ordered'];
     }
     try {
         $writeResult = $this->collection->getCollection()->bulkWrite($this->items, $options);
         $resultDocument = [];
         $ok = true;
     } catch (BulkWriteException $e) {
         $writeResult = $e->getWriteResult();
         $resultDocument = ['writeErrors' => $this->convertWriteErrors($writeResult)];
         $ok = false;
     }
     $this->items = [];
     switch ($this->batchType) {
         case self::COMMAND_UPDATE:
             $upsertedIds = [];
             foreach ($writeResult->getUpsertedIds() as $index => $id) {
                 $upsertedIds[] = ['index' => $index, '_id' => TypeConverter::toLegacy($id)];
             }
             $resultDocument += ['nMatched' => $writeResult->getMatchedCount(), 'nModified' => $writeResult->getModifiedCount(), 'nUpserted' => $writeResult->getUpsertedCount(), 'ok' => true];
             if (count($upsertedIds)) {
                 $resultDocument['upserted'] = $upsertedIds;
             }
             break;
         case self::COMMAND_DELETE:
             $resultDocument += ['nRemoved' => $writeResult->getDeletedCount(), 'ok' => true];
             break;
         case self::COMMAND_INSERT:
             $resultDocument += ['nInserted' => $writeResult->getInsertedCount(), 'ok' => true];
             break;
     }
     if (!$ok) {
         // Exception code is hardcoded to the value in ext-mongo, see
         // https://github.com/mongodb/mongo-php-driver-legacy/blob/ab4bc0d90e93b3f247f6bcb386d0abc8d2fa7d74/batch/write.c#L428
         throw new \MongoWriteConcernException('Failed write', 911, null, $resultDocument);
     }
     return $resultDocument;
 }
开发者ID:alcaeus,项目名称:mongo-php-adapter,代码行数:58,代码来源:MongoWriteBatch.php

示例4: execute

 /**
  * Executes a batch of write operations
  *
  * @see http://php.net/manual/en/mongowritebatch.execute.php
  * @param array $writeOptions
  * @return array
  */
 public final function execute(array $writeOptions = [])
 {
     $writeOptions += $this->writeOptions;
     if (!count($this->items)) {
         return ['ok' => true];
     }
     if (isset($writeOptions['j'])) {
         trigger_error('j parameter is not supported', E_WARNING);
     }
     if (isset($writeOptions['fsync'])) {
         trigger_error('fsync parameter is not supported', E_WARNING);
     }
     $options['writeConcern'] = $this->createWriteConcernFromArray($writeOptions);
     if (isset($writeOptions['ordered'])) {
         $options['ordered'] = $writeOptions['ordered'];
     }
     $collection = $this->collection->getCollection();
     try {
         $result = $collection->BulkWrite($this->items, $options);
         $ok = true;
     } catch (\MongoDB\Driver\Exception\BulkWriteException $e) {
         $result = $e->getWriteResult();
         $ok = false;
     }
     if ($ok === true) {
         $this->items = [];
     }
     switch ($this->batchType) {
         case self::COMMAND_UPDATE:
             $upsertedIds = [];
             foreach ($result->getUpsertedIds() as $index => $id) {
                 $upsertedIds[] = ['index' => $index, '_id' => TypeConverter::toLegacy($id)];
             }
             $result = ['nMatched' => $result->getMatchedCount(), 'nModified' => $result->getModifiedCount(), 'nUpserted' => $result->getUpsertedCount(), 'ok' => $ok];
             if (count($upsertedIds)) {
                 $result['upserted'] = $upsertedIds;
             }
             return $result;
         case self::COMMAND_DELETE:
             return ['nRemoved' => $result->getDeletedCount(), 'ok' => $ok];
         case self::COMMAND_INSERT:
             return ['nInserted' => $result->getInsertedCount(), 'ok' => $ok];
     }
 }
开发者ID:researchgate,项目名称:mongo-php-adapter,代码行数:51,代码来源:MongoWriteBatch.php


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