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


PHP MongoCollection::find方法代码示例

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


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

示例1: find

 /**
  * @param QueryInterface $query
  * @param ModelInterface $model
  * @return ModelListInterface
  * @throws NotSupportedFilterException
  */
 public function find(QueryInterface $query, ModelInterface $model)
 {
     $queryArray = array();
     foreach ($query->getFilters() as $filter) {
         if (!in_array(get_class($filter), self::$supportedFilters)) {
             throw new NotSupportedFilterException(sprintf('%s filter is not supported or unknown.', get_class($filter)));
         }
         $queryArray[$filter->getFieldName()] = $filter->getValue();
     }
     $list = new ModelList();
     $cursor = $this->collection->find($queryArray);
     if ($query->getLimit() !== null) {
         $cursor->limit($query->getLimit());
     }
     if ($query->getOffset() !== null) {
         $cursor->skip($query->getOffset());
     }
     foreach ($cursor as $doc) {
         unset($doc['_id']);
         /** @var ModelInterface $item */
         $item = new $model();
         $item->loadData($doc);
         if ($item instanceof SavableModelInterface) {
             $item->markAsStored();
         }
         $list->addListItem($item);
     }
     return $list;
 }
开发者ID:systream,项目名称:repository,代码行数:35,代码来源:MongoStoragePHP5.php

示例2: select

 public function select($collectionName, $limit, $skip, $sort)
 {
     #gelen $tableName isimli collectiona bağlantı gerçekleştirelim.
     $Collection = new MongoCollection($this->mongodb, $collectionName);
     //controllerdan limit diye birşey gelmiyorsa
     if ($limit != '') {
         $limit = $limit;
     } else {
         $limit = 0;
     }
     //skip yani limit 5 den 10 a gibi
     if ($skip != '') {
         $skip = $skip;
     } else {
         $skip = 0;
     }
     //controllerdan sort diye bir sıralama geliyorsa
     if ($sort != '') {
         try {
             $selectResult = $Collection->find()->skip($skip)->limit($limit)->sort($sort);
         } catch (MongoCursorException $e) {
             die('select yaparken teknik bir sorunla karşılaşıldı ' . $e->getMessage());
         }
     } else {
         try {
             $selectResult = $Collection->find()->skip($skip)->limit($limit);
         } catch (MongoCursorException $e) {
             die('Select yaparken teknik bir sorunla karşılaşıldı ' . $e->getMessage());
         }
     }
     return $selectResult;
 }
开发者ID:savashan0019,项目名称:MobilyaWeb,代码行数:32,代码来源:MongoDatabase.php

示例3: find

 public function find($criteria = [], $start = 0, $count = 20, $sortBy = null)
 {
     $cursor = $this->collection->find($criteria);
     if (is_numeric($start)) {
         $cursor->skip($start);
     }
     if (is_numeric($count)) {
         $cursor->limit($count);
     }
     if (is_array($sortBy)) {
         $cursor->sort($sortBy);
     }
     if ($cursor == null || $cursor->count(true) == 0) {
         return null;
     }
     if ($count == 1) {
         return new $this->entityClass($cursor->getNext());
     } else {
         $entities = [];
         foreach ($cursor as $r) {
             $entities[] = new $this->entityClass($r);
         }
         return $entities;
     }
 }
开发者ID:hoangpt,项目名称:nextcms,代码行数:25,代码来源:AbstractMapper.php

示例4: getLogsQueryBuilder

 /**
  * Initialize a QueryBuilder of latest log entries.
  *
  * @param $page
  * @param $logsPerPage
  * @param array $search
  * @return array
  */
 private function getLogsQueryBuilder($page, $logsPerPage, $search = array())
 {
     $skip = $logsPerPage * ($page - 1);
     $cursor = $this->collection->find($search);
     $cursor->skip($skip)->limit($logsPerPage)->sort(array('_id' => -1));
     return array('total' => $cursor->count(), 'results' => array_map([$this, 'convertArrayToEntity'], iterator_to_array($cursor)), 'search' => $search);
 }
开发者ID:jhamilton86,项目名称:MongologBrowserBundle,代码行数:15,代码来源:LogRepository.php

示例5: count

 /**
  * Zwraca liczbę elementów
  *
  * @return	int
  */
 public function count()
 {
     if ($this->iCount === null) {
         $this->iCount = $this->oColl->find($this->aQuery, $this->aFields)->count(true);
     }
     return $this->iCount;
 }
开发者ID:pt-pl,项目名称:zf2-data-object,代码行数:12,代码来源:Adapter.php

示例6: deleteExceedingQuota

 public function deleteExceedingQuota($quota)
 {
     $threshold = 0.9 * $quota;
     $currentSize = $this->getPictureTotalSize();
     $counter = 0;
     if ($currentSize > $threshold) {
         $toPurge = $currentSize - $threshold;
         // cleaning
         $cursor = $this->collection->find(['-class' => 'picture'], ['storageKey' => true, 'size' => true])->sort(['_id' => 1]);
         // starting from older pictures
         $sum = 0;
         foreach ($cursor as $item) {
             if ($sum < $toPurge) {
                 $this->storage->remove($item['storageKey']);
                 $this->collection->remove(['_id' => $item['_id']]);
                 $sum += $item['size'];
                 $counter++;
             } else {
                 // when we have deleted enough old pictures to reach the exceeding size to purge
                 break;
             }
         }
     }
     return $counter;
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:25,代码来源:StorageQuota.php

示例7: getResultSet

 /**
  * MapReduce Result Set
  * @return MongoCursor
  */
 public function getResultSet(array $query = array())
 {
     if (!isset($this->collection)) {
         $this->collection = new MongoCollection($this->mongoDB, $this->_response["result"]);
     }
     return $this->collection->find($query);
 }
开发者ID:rjdjohnston,项目名称:MongoDB-MapReduce-PHP,代码行数:11,代码来源:MongoMapReduceResponse.php

示例8: loadTag

 /**
  * {@inheritdoc}
  */
 public function loadTag($tag)
 {
     $cache = $this->collection->find(array('tags' => $this->mapTag($tag)), array('key'));
     $keys = array_map(function ($v) {
         return $v['key'];
     }, array_values(iterator_to_array($cache)));
     return empty($keys) ? null : $keys;
 }
开发者ID:vidyatestghe,项目名称:apix-cache,代码行数:11,代码来源:Mongo.php

示例9: getForAccount

 /**
  * @param AccountId $accountId
  * @return ExpenseListInOverview[]
  */
 public function getForAccount(AccountId $accountId)
 {
     $expenseLists = [];
     foreach ($this->collection->find(['accountId' => (string) $accountId]) as $expenseList) {
         $expenseLists[] = ExpenseListInOverview::deserialize($expenseList);
     }
     return $expenseLists;
 }
开发者ID:gobudgit,项目名称:gobudgit,代码行数:12,代码来源:MongoExpenseListInOverviewRepository.php

示例10: findAll

 public function findAll()
 {
     $all = $this->contactsManagerCollection->find();
     $contacts = array();
     foreach ($all as $item) {
         $contacts[] = $this->createContact($item);
     }
     return $contacts;
 }
开发者ID:lga37,项目名称:contacts,代码行数:9,代码来源:ContactMongoStorage.php

示例11: find

 public function find($source)
 {
     $targets = $this->_collection->find(array('source' => $source), array('source' => false));
     $ret = array();
     foreach ($targets as $t) {
         $ret[] = (string) $t['_id'];
     }
     return $ret;
 }
开发者ID:laiello,项目名称:oops-project,代码行数:9,代码来源:Mongodb.php

示例12: get_all

 /** Получение всех статей
  * @return array Result or null
  */
 public function get_all()
 {
     $coursor = ArticlesCollection::$collection->find();
     if ($coursor->count() == 0) {
         return null;
     }
     foreach ($coursor as $document) {
         $articles[] = $document;
     }
     return $articles;
 }
开发者ID:ChupinDO,项目名称:blog_mongodb,代码行数:14,代码来源:ArticlesCollection.php

示例13: testWrite

 public function testWrite()
 {
     $id = "somekey";
     $value = "Foo";
     $this->assertEquals(null, $this->collection->findOne());
     $cache = SS_Cache::factory(self::$cache_name);
     /** @var ICacheFrontend$cache */
     $cache->save($value, $id);
     $this->assertEquals(1, $this->collection->find()->count());
     $this->assertEquals($value, $this->collection->find()->getNext()['content']);
 }
开发者ID:notthatbad,项目名称:silverstripe-caching,代码行数:11,代码来源:MongoCacheBackendTest.php

示例14: 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

示例15: getDocuments

 /**
  * Get a Document from the DocumentStore
  * @param array $ids IDs of Documents to get
  * @return array Documents matching $ids
  */
 public function getDocuments($ids)
 {
     $results = [];
     $documents = $this->documents->find(['id' => ['$in' => $ids]]);
     foreach ($documents as $result) {
         $document = new Document($result['title'], $result['content']);
         $document->id = $result['id'];
         $document->tokens = $result['tokens'];
         $results[$document->id] = $document;
     }
     return $results;
 }
开发者ID:markusos,项目名称:simple-search,代码行数:17,代码来源:MongoDBDocumentStore.php


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