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


PHP MongoCollection::count方法代码示例

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


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

示例1: has

 /**
  * {@inheritdoc }
  */
 public function has($key)
 {
     $tKey = $this->getKey($key);
     $tNow = $this->getTtl();
     return $this->collection->count(array('_id' => $tKey, 'ttl' => array('$gte' => $tNow))) > 0;
 }
开发者ID:evolutionscript,项目名称:Cache,代码行数:9,代码来源:Mongo.php

示例2: count

 /**
  * count.
  */
 public function count($query = array(), $limit = 0, $skip = 0)
 {
     $this->time->start();
     $return = parent::count($query, $limit, $skip);
     $time = $this->time->stop();
     $this->log(array('type' => 'count', 'query' => $query, 'limit' => $limit, 'skip' => $skip, 'time' => $time));
     return $return;
 }
开发者ID:hybr,项目名称:jpm,代码行数:11,代码来源:LoggableMongoCollection.php

示例3: count

 /**
  * Counts the number of documents in the model's collection
  * @param array $options Options for the count query.
  * @param array $limit Specifies an upper limit to the number returned
  * @param array $skip Specifies a number of results to skip before starting the count.
  * @return int Returns the number of documents matching the query.
  */
 public function count($query = array(), $limit = 0, $skip = 0)
 {
     if ($query === null) {
         $query = array();
     } else {
         $query = self::_sanitize($query);
     }
     return $this->collection->count($query, $limit, $skip);
 }
开发者ID:mindaugas-valinskis,项目名称:doophp,代码行数:16,代码来源:DooMongoModel.php

示例4: count

 /**
  * Gets back the number of documents viewed, if nothing viewed then it's zero
  * 
  * @param Array $criteria the condition for gretting how many back
  * @return int 
  */
 public function count($criteria = array())
 {
     ValidatorsUtil::isNullOrEmpty($this->_mongoCollection, "Mongo collection isn't valid, have you set a collection?");
     $documentCount = 0;
     if (count($criteria) != 0) {
         $documentCount = $this->_mongoCollection->count($criteria);
     } else {
         $documentCount = $this->_mongoCollection->count();
     }
     return $documentCount;
 }
开发者ID:retrogamer4ever,项目名称:php-tools,代码行数:17,代码来源:MongoConnection.php

示例5: numberOfRecipients

 /**
  */
 public function numberOfRecipients($hours, $user = false)
 {
     $query = array(self::SUCCESS => 1, self::TS => array('$gt' => time() - $hours * 3600));
     if ($user) {
         $query[self::WHO] = $GLOBALS['registry']->getAuth();
     }
     try {
         return $this->_db->count($query);
     } catch (MongoException $e) {
         return 0;
     }
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:14,代码来源:Mongo.php

示例6: up

 /**
  * Removes documents from the client collection that have
  * an lrs_id that does not exist in the lrs collection.
  *
  * @return void
  */
 public function up()
 {
     $db = \DB::getMongoDB();
     $clients = new MongoCollection($db, 'client');
     $lrss = new MongoCollection($db, 'lrs');
     $clientCursor = $clients->find([], ['lrs_id' => true]);
     foreach ($clientCursor as $client) {
         $count = $lrss->count(['_id' => $client['lrs_id']]);
         if ($count == 0) {
             $clients->remove(['_id' => $client['_id']]);
         }
     }
 }
开发者ID:scmc,项目名称:learninglocker,代码行数:19,代码来源:2015_09_15_105751_remove_orphan_clients.php

示例7: count

 /**
  * @param array|stdClass $query
  * @param null $limit
  * @param null $skip
  * @return int
  */
 public function count($query = [], $limit = null, $skip = null)
 {
     $options = $limit;
     if (is_array($options) && isset($options['cache']) && $options['cache'] === false) {
         return parent::count($query);
     }
     $hash = $this->hash($query);
     $result = $this->cache->get($hash);
     if (!$result) {
         $result = parent::count($query);
         $this->cache->set($hash, $result, $this->getCacheTime($options));
     }
     return $result;
 }
开发者ID:nicklasos,项目名称:MongoCache,代码行数:20,代码来源:MongoCollection.php

示例8: testSave

 public function testSave()
 {
     $this->object->save(array('x' => 1));
     $a = $this->object->findOne();
     $id1 = $a['_id'];
     $a['x'] = 2;
     $this->object->save($a);
     $id2 = $a['_id'];
     $this->assertEquals($id1, $id2);
     $a['y'] = 3;
     $this->object->save($a);
     $this->assertEquals($this->object->count(), 1);
     $a = $this->object->findOne();
     $this->assertEquals($a['x'], 2);
 }
开发者ID:salathe,项目名称:mongo-php-driver,代码行数:15,代码来源:MongoCollectionTest.php

示例9: count

 /**
  * Count queue messages.
  *
  * @param array $query in same format as \MongoCollection::find() where top level fields do not contain operators.
  * Lower level fields can however. eg: valid {a: {$gt: 1}, "b.c": 3}, invalid {$and: [{...}, {...}]}
  * @param bool|null $qr query a running message or not or all
  *
  * @return int the count
  *
  * @throws \InvalidArgumentException $qr was not null and not a bool
  * @throws \InvalidArgumentException key in $query was not a string
  */
 public function count(array $query, $qr = null)
 {
     if ($qr !== null && !is_bool($qr)) {
         throw new \InvalidArgumentException('$qr was not null and not a bool');
     }
     $totalQuery = array();
     if ($qr !== null) {
         $totalQuery['qr'] = $qr;
     }
     foreach ($query as $key => $value) {
         if (!is_string($key)) {
             throw new \InvalidArgumentException('key in $query was not a string');
         }
         $totalQuery["payload.{$key}"] = $value;
     }
     return $this->_collection->count($totalQuery);
 }
开发者ID:diffion,项目名称:php-mongo-queue,代码行数:29,代码来源:Queue.php

示例10: testGarbageCollection

 public function testGarbageCollection()
 {
     $saveHandler = new MongoDB($this->mongo, $this->options);
     $this->assertTrue($saveHandler->open('savepath', 'sessionname'));
     $data = array('foo' => 'bar');
     $this->assertTrue($saveHandler->write(123, serialize($data)));
     $this->assertTrue($saveHandler->write(456, serialize($data)));
     $this->assertEquals(2, $this->mongoCollection->count());
     $saveHandler->gc(5);
     $this->assertEquals(2, $this->mongoCollection->count());
     /* Note: MongoDate uses micro-second precision, so even a maximum
      * lifetime of zero would not match records that were just inserted.
      * Use a negative number instead.
      */
     $saveHandler->gc(-1);
     $this->assertEquals(0, $this->mongoCollection->count());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:17,代码来源:MongoDBTest.php

示例11: read

 /**
  */
 public function read($id)
 {
     /* Check for session existence. Unfortunately needed because
      * we need findAndModify() for its atomicity for locking, but this
      * atomicity means we can't tell the difference between a
      * non-existent session and a locked session. */
     $exists = $this->_db->count(array(self::SID => $id));
     $exist_check = false;
     $i = 0;
     /* Set a maximum unlocking time, to prevent runaway PHP processes. */
     $max = ini_get('max_execution_time') * 10;
     while (true) {
         $data = array(self::LOCK => time(), self::SID => $id);
         /* This call will either create the session if it doesn't exist,
          * or will update the current session and lock it if not already
          * locked. If a session exists, and is locked, $res will contain
          * an empty set and we need to sleep and wait for lock to be
          * removed. */
         $res = $this->_db->findAndModify(array(self::SID => $id, self::LOCK => array('$exists' => $exist_check)), array($data), array(self::DATA => true), array('update' => array('$set' => $data), 'upsert' => !$exists));
         if (!$exists || isset($res[self::DATA])) {
             break;
         }
         /* After a second, check the timestamp to determine if this is
          * a stale session. This can prevent long waits on a busted PHP
          * process. */
         if ($i == 10) {
             $res = $this->_db->findOne(array(self::SID => $id), array(self::LOCK => true));
             $max = isset($res[self::LOCK]) ? (time() - $res[self::LOCK]) * 10 : $i;
         }
         if (++$i >= $max) {
             $exist_check = true;
         } else {
             /* Sleep for 0.1 second before trying again. */
             usleep(100000);
         }
     }
     $this->_locked = $id;
     return isset($res[self::DATA]) ? $res[self::DATA]->bin : '';
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:41,代码来源:Mongo.php

示例12: size

 /**
  * Get the number of indexed terms
  * @return integer Number of indexed terms
  */
 public function size()
 {
     return $this->index->count();
 }
开发者ID:markusos,项目名称:simple-search,代码行数:8,代码来源:MongoDBDocumentIndex.php

示例13: update

 /**
  * 更新指定范围的数据
  *
  * @param array $criteria            
  * @param array $object            
  * @param array $options            
  */
 public function update($criteria, $object, array $options = NULL)
 {
     if (!is_array($criteria)) {
         throw new \Exception('$criteria is array');
     }
     if (empty($object)) {
         throw new \Exception('$object is empty');
     }
     $keys = array_keys($object);
     foreach ($keys as $key) {
         // $key = strtolower($key);
         if (!in_array($key, $this->_updateHaystack, true)) {
             throw new \Exception('$key must contain ' . join(',', $this->_updateHaystack));
         }
     }
     $default = array('upsert' => self::upsert, 'multiple' => self::multiple, 'fsync' => self::fsync);
     $options = $options === NULL ? $default : array_merge($default, $options);
     $criteria = $this->appendQuery($criteria);
     array_unset_recursive($object, array('_id', '__CREATE_TIME__', '__MODIFY_TIME__', '__REMOVED__'));
     if (parent::count($criteria) == 0) {
         if (isset($options['upsert']) && $options['upsert']) {
             $criteria = $this->addSharedKeyToQuery($criteria);
             parent::update($criteria, array('$set' => array('__CREATE_TIME__' => new \MongoDate(), '__MODIFY_TIME__' => new \MongoDate(), '__REMOVED__' => false)), $options);
         }
     } else {
         unset($options['upsert']);
         parent::update($criteria, array('$set' => array('__MODIFY_TIME__' => new \MongoDate())), $options);
     }
     return parent::update($criteria, $object, $options);
 }
开发者ID:im286er,项目名称:ent,代码行数:37,代码来源:MongoCollection.php

示例14: _call

 protected function _call($command, array $arguments = array(), array $values = NULL)
 {
     $start = microtime(true);
     $this->_connected or $this->connect();
     extract($arguments);
     if (isset($collection_name)) {
         $c = new \MongoCollection($this->_db, $collection_name);
     }
     switch ($command) {
         case 'ensure_index':
             $r = $c->ensureIndex($keys, $options);
             break;
         case 'create_collection':
             $r = $this->_db->createCollection($name, $capped, $size, $max);
             break;
         case 'drop_collection':
             $r = $this->_db->dropCollection($name);
             break;
         case 'command':
             $r = $this->_db->command($values);
             break;
         case 'execute':
             $r = $this->_db->execute($code, $args);
             break;
         case 'batch_insert':
             $r = $c->batchInsert($values);
             break;
         case 'count':
             $r = $c->count($query);
             break;
         case 'find_one':
             $r = $c->findOne($query, $fields);
             break;
         case 'find':
             $r = $c->find($query, $fields);
             break;
         case 'group':
             $r = $c->group($keys, $initial, $reduce, $condition);
             break;
         case 'update':
             $r = $c->update($criteria, $values, $options);
             break;
         case 'insert':
             $r = $c->insert($values, $options);
             return $values;
             break;
         case 'remove':
             $r = $c->remove($criteria, $options);
             break;
         case 'save':
             $r = $c->save($values, $options);
             break;
         case 'get_file':
             $r = $this->gridFS()->findOne($criteria);
             break;
         case 'get_files':
             $r = $this->gridFS()->find($query, $fields);
             break;
         case 'set_file_bytes':
             $r = $this->gridFS()->storeBytes($bytes, $extra, $options);
             break;
         case 'set_file':
             $r = $this->gridFS()->storeFile($filename, $extra, $options);
             break;
         case 'remove_file':
             $r = $this->gridFS()->remove($criteria, $options);
             break;
     }
     $this->log($command, $start, $arguments);
     return $r;
 }
开发者ID:SerdarSanri,项目名称:mongor,代码行数:71,代码来源:mongodb.php

示例15: getCount

 /**
  * 
  * @return int
  */
 public function getCount()
 {
     return $this->cacheGet('statistics/count', function () {
         return $this->collection->count();
     });
 }
开发者ID:mflayhart,项目名称:gw2tools,代码行数:10,代码来源:Statistics.php


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