本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例10: findAll
public function findAll()
{
$all = $this->contactsManagerCollection->find();
$contacts = array();
foreach ($all as $item) {
$contacts[] = $this->createContact($item);
}
return $contacts;
}
示例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;
}
示例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;
}
示例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']);
}
示例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));
}
示例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;
}