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

From: Date: Thu, 08 Jul 2010 14:17:34 +0000
Subject: svn: /phpdoc/en/trunk/reference/mongo/mongocollection/ group.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6873@lists.php.net to get a copy of this message
kristina Thu, 08 Jul 2010 14:17:34 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=301082 Log: better group examples 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-07-08 14:05:11 UTC (rev 301081) +++ phpdoc/en/trunk/reference/mongo/mongocollection/group.xml 2010-07-08 14:17:34 UTC (rev 301082) @@ -14,7 +14,7 @@ <methodparam><type>mixed</type><parameter>keys</parameter></methodparam> <methodparam><type>array</type><parameter>initial</parameter></methodparam> <methodparam><type>MongoCode</type><parameter>reduce</parameter></methodparam> - <methodparam choice="opt"><type>array</type><parameter>condition</parameter><initializer>array()</initializer></methodparam> + <methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam> </methodsynopsis> </refsect1> @@ -103,10 +103,52 @@ &reftitle.examples; <example> <title><function>MongoCollection::group</function> example</title> + <para> + This groups documents by category and creates a list of names within that + category. + </para> <programlisting role="php"> <![CDATA[ <?php +$collection->insert(array("category" => "fruit", "name" => "apple")); +$collection->insert(array("category" => "fruit", "name" => "peach")); +$collection->insert(array("category" => "fruit", "name" => "banana")); +$collection->insert(array("category" => "veggie", "name" => "corn")); +$collection->insert(array("category" => "veggie", "name" => "broccoli")); + +$keys = array("category" => 1); + +$initial = array("items" => array()); + +$reduce = "function (obj, prev) { prev.items.push(obj.name); }"; + +$g = $collection->group($keys, $initial, $reduce); + +echo json_encode($g['retval']); + +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +[{"category":"fruit","items":["apple","peach","banana"]},{"category":"veggie","items":["corn","broccoli"]}] +]]> + </screen> + </example> + + <example> + <title><function>MongoCollection::group</function> example</title> + <para> + This example doesn't use any key, so every document will be its own group. + It also uses a condition: only documents that match this condition will be + processed by the grouping function. + </para> + <programlisting role="php"> +<![CDATA[ +<?php + $collection->save(array("a" => 2)); $collection->save(array("b" => 5)); $collection->save(array("a" => 1));

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