php-doc-en/reference/mongo/mongocollection/group.xml
Kristina Chodorow b3808ede9d fixed group output
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@289215 c90b9560-bf6c-de11-be94-00142212c4b1
2009-10-05 14:15:15 +00:00

150 lines
3.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocollection.group" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCollection::group</refname>
<refpurpose>Performs an operation similar to SQL's GROUP BY command</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>array</type><methodname>MongoCollection::group</methodname>
<methodparam><type>array</type><parameter>keys</parameter></methodparam>
<methodparam><type>array</type><parameter>initial</parameter></methodparam>
<methodparam><type>string</type><parameter>reduce</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>condition</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>keys</parameter>
</term>
<listitem>
<para>
Fields to group by.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>initial</parameter>
</term>
<listitem>
<para>
Initial value of the aggregation counter object.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>reduce</parameter>
</term>
<listitem>
<para>
A function that aggregates (reduces) the objects iterated.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>condition</parameter>
</term>
<listitem>
<para>
An condition that must be true for a row to be considered.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns an array containing the result.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCollection::group</function> example</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(4) {
["retval"]=>
array(1) {
[0]=>
array(1) {
["count"]=>
float(1)
}
}
["count"]=>
float(1)
["keys"]=>
int(1)
["ok"]=>
float(1)
}
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->