mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Document new mehtod in 1.3.0 MongoCollection::aggregate()
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@327444 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
c5849e0c38
commit
1c964dfab8
2 changed files with 187 additions and 0 deletions
186
reference/mongo/mongocollection/aggregate.xml
Normal file
186
reference/mongo/mongocollection/aggregate.xml
Normal file
|
@ -0,0 +1,186 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<refentry xml:id="mongocollection.aggregate" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoCollection::aggregate</refname>
|
||||
<refpurpose>Perform an aggregation using the aggregation framework</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>array</type><methodname>MongoCollection::aggregate</methodname>
|
||||
<methodparam><type>array</type><parameter>pipelines</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>array</type><parameter>pipeline</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>array</type><parameter>..</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
The MongoDB <link xlink:href="&url.mongodb.docs.aggregation;">aggregation framework</link> provides a means to calculate aggregated
|
||||
values without having to use map-reduce. While map-reduce is powerful, it is
|
||||
often more difficult than necessary for many simple aggregation tasks, such
|
||||
as totaling or averaging field values.
|
||||
</para>
|
||||
<para>
|
||||
This method accepts both variable amount of
|
||||
<parameter>pipeline</parameter>s, or an array of <parameter>pipelines</parameter>.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><parameter>pipelines</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
An array of <parameter>>pipeline</parameter>s, or just the first part.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><parameter>pipeline</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Second array of pipes.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><parameter>..</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
More pippes...
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
The result of the aggregation as an array.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<example xml:id="mongocollection.aggregate.example.basic">
|
||||
<title><methodname>MongoCollection::aggregate</methodname> example</title>
|
||||
<para>
|
||||
The following example aggregation operation pivots data to create a set of
|
||||
author names grouped by tags applied to an article. Call the aggregation
|
||||
framework by issuing the following command:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
$m = new Mongo;
|
||||
$c = $m->selectDB("examples")->selectCollection("article");
|
||||
$c->drop();
|
||||
$data = array (
|
||||
'title' => 'this is my title',
|
||||
'author' => 'bob',
|
||||
'posted' => new MongoDate,
|
||||
'pageViews' => 5,
|
||||
'tags' => array ( 'fun', 'good', 'fun' ),
|
||||
'comments' => array (
|
||||
array (
|
||||
'author' => 'joe',
|
||||
'text' => 'this is cool',
|
||||
),
|
||||
array (
|
||||
'author' => 'sam',
|
||||
'text' => 'this is bad',
|
||||
),
|
||||
),
|
||||
'other' =>array (
|
||||
'foo' => 5,
|
||||
),
|
||||
);
|
||||
$d = $c->insert($data, array("safe" => true));
|
||||
|
||||
$ops = array(
|
||||
array(
|
||||
'$project' => array(
|
||||
"author" => 1,
|
||||
"tags" => 1,
|
||||
)
|
||||
),
|
||||
array('$unwind' => '$tags'),
|
||||
array(
|
||||
'$group' => array(
|
||||
"_id" => array("tags" => 1),
|
||||
"authors" => array('$addToSet' => '$author'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$results = $c->aggregate($ops);
|
||||
var_dump($results);
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
["_id"]=>
|
||||
array(1) {
|
||||
["tags"]=>
|
||||
string(4) "good"
|
||||
}
|
||||
["authors"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(3) "bob"
|
||||
}
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
["_id"]=>
|
||||
array(1) {
|
||||
["tags"]=>
|
||||
string(3) "fun"
|
||||
}
|
||||
["authors"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(3) "bob"
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<simplelist>
|
||||
<member>The MongoDB <link xlink:href="&url.mongodb.docs.aggregation;">aggregation framework</link></member>
|
||||
</simplelist>
|
||||
</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
|
||||
indent-tabs-mode:nil
|
||||
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
|
||||
-->
|
|
@ -56,6 +56,7 @@
|
|||
<function name='mongocollection::__construct' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::__tostring' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::__get' from='PECL mongo >=1.0.2'/>
|
||||
<function name='mongocollection::aggregate' from='PECL mongo >=1.3.0'/>
|
||||
<function name='mongocollection::getname' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::count' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::deleteindex' from='PECL mongo >=0.9.0'/>
|
||||
|
|
Loading…
Reference in a new issue