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


PHP MongoCollection::group方法代码示例

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


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

示例1: testGroup2

 public function testGroup2()
 {
     $this->object->save(array("a" => 2));
     $this->object->save(array("b" => 5));
     $this->object->save(array("a" => 1));
     $keys = array();
     $initial = array("count" => 0);
     $reduce = "function (obj, prev) { prev.count++; }";
     $g = $this->object->group($keys, $initial, $reduce);
     $this->assertEquals(3, $g['count']);
 }
开发者ID:salathe,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoCollectionTest.php

示例2: testGroupFinalize2

 public function testGroupFinalize2()
 {
     for ($i = 0; $i < 100; $i++) {
         $this->object->insert(array("x" => $i, "y" => $i % 7, "z" => "foo{$i}"));
     }
     $result = $this->object->group(array("y" => 1), array("count" => 0), "function(cur, prev) { prev.count++; }", array("finalize" => "function(out) { return 1; }"));
     $this->assertEquals(true, (bool) $result['ok'], json_encode($result));
     foreach ($result['retval'] as $val) {
         $this->assertEquals(1, $val);
     }
     $this->assertEquals(100, $result['count']);
     $this->assertEquals(7, $result['keys']);
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:13,代码来源:MongoCollectionTest.php

示例3: testGroup

 public function testGroup()
 {
     $g = $this->object->group(array(), array("count" => 0), "function (obj, prev) { prev.count++; }", array());
     $this->assertEquals(0, count($g['retval']));
     $this->object->save(array("a" => 2));
     $this->object->save(array("b" => 5));
     $this->object->save(array("a" => 1));
     $g = $this->object->group(array(), array("count" => 0), "function (obj, prev) { prev.count++; }", array());
     $this->assertEquals(1, count($g['retval']));
     $this->assertEquals(3, $g['retval'][0]['count']);
     $g = $this->object->group(array(), array("count" => 0), "function (obj, prev) { prev.count++; }", array("a" => array('$gt' => 1)));
     $this->assertEquals(1, count($g['retval']));
     $this->assertEquals(1, $g['retval'][0]['count']);
 }
开发者ID:petewarden,项目名称:mongo-php-driver,代码行数:14,代码来源:MongoCollectionTest.php

示例4: group

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

示例5: _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

示例6: doGroup

 protected function doGroup($keys, array $initial, $reduce, array $options)
 {
     $result = $this->mongoCollection->group($keys, $initial, $reduce, $options);
     return new ArrayIterator($result);
 }
开发者ID:rybakit,项目名称:mongodb,代码行数:5,代码来源:Collection.php


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