MongoCollection::getName
MongoCollection::insert
MongoCollection
PHP Manual

# MongoCollection::group

(PECL mongo >=0.9.2)

MongoCollection::group — Performs an operation similar to SQL's GROUP BY command

### 설명

public array MongoCollection::group ( array `$keys` , array `$initial` , string `$reduce` [, array `$condition`= array() ] )

### 인수

`keys`

  Fields to group by.

`initial`

  Initial value of the aggregation counter object.

`reduce`

  A function that aggregates (reduces) the objects iterated.

`condition`

  An condition that must be true for a row to be considered.

### 반환값

Returns an array containing the result.

### 예제

Example #1 MongoCollection::group() example

`<?php
$collection->save(array("a" => 2));
$collection->save(array("b" => 5));
$collection->save(array("a" => 1));
// use all fields
$keys = array();
// set intial values
$initial = array("count" => 0);
// JavaScript function to perform
$reduce = "function (obj, prev) { prev.count++; }";
// only use documents where the "a" field is greater than 1
$condition = array("a" => array( '$gt' => 1));
$g = $collection->group($keys, $initial, $reduce, $condition);
var_dump($g);
?>`

위 예제의 출력 예시:

    array(1) {
      [0]=>
      array(1) {
        ["count"]=>
        int(1)
      }
    }

MongoCollection::getName
MongoCollection::insert
MongoCollection
PHP Manual