svn: /phpdoc/en/trunk/reference/mongo/mongocollection/ group.xml

From: Date: Mon, 01 Mar 2010 21:42:32 +0000
Subject: svn: /phpdoc/en/trunk/reference/mongo/mongocollection/ group.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6149@lists.php.net to get a copy of this message
kristina Mon, 01 Mar 2010 21:42:32 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=295691 Log: added MongoCode keyf Changed paths: U phpdoc/en/trunk/reference/mongo/mongocollection/group.xml Modified: phpdoc/en/trunk/reference/mongo/mongocollection/group.xml =================================================================== --- phpdoc/en/trunk/reference/mongo/mongocollection/group.xml 2010-03-01 21:09:41 UTC (rev 295690) +++ phpdoc/en/trunk/reference/mongo/mongocollection/group.xml 2010-03-01 21:42:32 UTC (rev 295691) @@ -11,9 +11,9 @@ &reftitle.description; <methodsynopsis> <modifier>public</modifier> <type>array</type><methodname>MongoCollection::group</methodname> - <methodparam><type>array</type><parameter>keys</parameter></methodparam> + <methodparam><type>mixed</type><parameter>keys</parameter></methodparam> <methodparam><type>array</type><parameter>initial</parameter></methodparam> - <methodparam><type>string</type><parameter>reduce</parameter></methodparam> + <methodparam><type>MongoCode</type><parameter>reduce</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>condition</parameter><initializer>array()</initializer></methodparam> </methodsynopsis> </refsect1> @@ -28,8 +28,14 @@ </term> <listitem> <para> - Fields to group by. + Fields to group by. If an array or non-code object is passed, it will be + the key used to group results. </para> + <para>1.0.4+: If <parameter>keys</parameter> is an instance of + <classname>MongoCode</classname>, <parameter>keys</parameter> will be treated as + a function that returns the key to group by (see the "Passing a + <parameter>keys</parameter> function" example below). + </para> </listitem> </varlistentry> <varlistentry> @@ -126,6 +132,33 @@ ]]> </screen> </example> + + <example> + <title>Passing a <parameter>keys</parameter> function</title> + <para> + If you want to group by something other than a field name, you can pass + a function as the first parameter of + <function>MongoCollection::group</function> and it will be run against each + document. The return value of the function will be used as its grouping + value. + </para> + <para> + This example demonstrates grouping by the num field modulo 4. + </para> + + <programlisting role="php"> +<![CDATA[ +<?php + +$c->group(new MongoCode('function(doc) { return {mod : doc.num % 4}; }'), + array("count" => 0), + new MongoCode('function(current, total) { total.count++; }')); + +?> +]]> + </programlisting> + </example> + </refsect1> </refentry>

« previous php.doc.cvs (#6149) next »