本文整理汇总了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']);
}
示例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']);
}
示例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']);
}
示例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;
}
示例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;
}
示例6: doGroup
protected function doGroup($keys, array $initial, $reduce, array $options)
{
$result = $this->mongoCollection->group($keys, $initial, $reduce, $options);
return new ArrayIterator($result);
}