mongodb\Command group()

group() public method

Performs aggregation using MongoDB "group" command.

public array group ( $collectionName, $keys, $initial, $reduce, $options = [] )
$collectionName string

Collection name.

$keys mixed

Fields to group by. If an array or non-code object is passed, it will be the key used to group results. If instance of \MongoDB\BSON\Javascript passed, it will be treated as a function that returns the key to group by.

$initial array

Initial value of the aggregation counter object.

$reduce \MongoDB\BSON\Javascript|string

Function that takes two arguments (the current document and the aggregation to this point) and does the aggregation. Argument will be automatically cast to \MongoDB\BSON\Javascript.

$options array

Optional parameters to the group command. Valid options include:

  • condition - criteria for including a document in the aggregation.
  • finalize - function called once per unique key that takes the final output of the reduce function.
return array

The result of the aggregation.

doc_Yii
2016-10-30 17:07:50
Comments
Leave a Comment

Please login to continue.