mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 07:52:21 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@337046 c90b9560-bf6c-de11-be94-00142212c4b1
233 lines
7.4 KiB
XML
233 lines
7.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 452d71c53cb8f32e6a4df407aeab9dfbeeaa5fcf Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xml:id="mongocollection.aggregatecursor" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>MongoCollection::aggregateCursor</refname>
|
|
<refpurpose>Ejecutar un comando de tubería acumulador y recuperar los resultados mediante un cursor</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier> <type>MongoCommandCursor</type><methodname>MongoCollection::aggregateCursor</methodname>
|
|
<methodparam><type>array</type><parameter>command</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>options</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Con este método se pueden ejecutar tuberías del Marco de Acumulación y
|
|
recuperar los resultados mediante un cursor, en lugar de obtener solamente un documento
|
|
tal como se haría con <methodname>MongoCollection::aggregate</methodname>.
|
|
Este método devuelve un objeto <classname>MongoCommandCursor</classname>.
|
|
Este objeto de cursor implementa la interfaz <classname>Iterator</classname>
|
|
al igual que los objetos <classname>MongoCursor</classname> devueltos por
|
|
el método <methodname>MongoCollection::find</methodname>.
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
El objeto <classname>MongoCommandCursor</classname> resultante heredará esta
|
|
preferencia de lectura de colección.
|
|
Se podría utilizar <methodname>MongoCommandCursor::setReadPreference</methodname>
|
|
para cambiar la preferencia de lectura antes de recorrer el cursor.
|
|
</simpara>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>pipeline</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
La tubería del Marco de Acumulación a ejecutar.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>options</parameter></term>
|
|
<listitem>
|
|
<para>Opciones para el comando acumulador. Las opciones válidas son:</para>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<para><literal>"allowDiskUse"</literal></para>
|
|
<para>Permitir que los estados acumulados se escriban en ficheros temporales</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>"cursor"</literal></para>
|
|
<para>
|
|
Es posible configurar cuántos documentos iniciales debería devolver el servidor
|
|
con el primer conjunto de resultados. El tamaño predeterminado del lote inicial
|
|
es <literal>101</literal>. Se puede cambiar este valor añadiendo la opción
|
|
<literal>batchSize</literal>:
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$colección->aggregateCursor(
|
|
$pipeline,
|
|
[ "cursor" => [ "batchSize" => 4 ] ]
|
|
);
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Esta opción solamente configura el tamaño del primer lote. Para configurar
|
|
el tamaño de los demás lotes, emplee el método
|
|
<methodname>MongoCommandCursor::batchSize</methodname> del objeto
|
|
<classname>MongoCommandCursor</classname> devuelto.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>"explain"</literal></para>
|
|
<para>
|
|
Devolver información del procesamiento de la tubería. Si fuera necesario
|
|
usar esta opción, se debería considerar el empleo de
|
|
<methodname>MongoCollection::aggregate</methodname>.
|
|
</para>
|
|
</listitem>
|
|
&mongo.command.parameters.maxtimems;
|
|
</itemizedlist>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve un objeto <classname>MongoCommandCursor</classname>. Puesto que
|
|
implementa la interfaz <classname>Iterator</classname>, se puede
|
|
recorrer cada uno de los resultados mientras los devuelve la consulta de comando.
|
|
<classname>MongoCommandCursor</classname> también implementa la interfaz
|
|
<classname>MongoCursorInterface</classname>, la cual añade los métodos
|
|
<methodname>MongoCommandCursor::batchSize</methodname>,
|
|
<methodname>MongoCommandCursor::dead</methodname> y
|
|
<methodname>MongoCommandCursor::info</methodname>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Ejemplo de <function>MongoCollection::aggregateCursor</function></title>
|
|
<para>
|
|
Encontrar todos los valores distintos de una clave.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$m = new MongoClient;
|
|
$db = $m->test;
|
|
$people = $db->people;
|
|
$people->drop();
|
|
|
|
$people->insert(array("name" => "Joe", "points" => 4));
|
|
$people->insert(array("name" => "Molly", "points" => 43));
|
|
$people->insert(array("name" => "Sally", "points" => 22));
|
|
$people->insert(array("name" => "Joe", "points" => 22));
|
|
$people->insert(array("name" => "Molly", "points" => 87));
|
|
|
|
$ages = $people->aggregateCursor( [
|
|
[ '$group' => [ '_id' => '$name', 'points' => [ '$sum' => '$points' ] ] ],
|
|
[ '$sort' => [ 'points' => -1 ] ],
|
|
] );
|
|
|
|
foreach ($ages as $person) {
|
|
echo "{$person['_id']}: {$person['points']}\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
Molly: 130
|
|
Joe: 26
|
|
Sally: 22
|
|
</screen>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Ejemplo de <function>MongoCollection::aggregateCursor</function>
|
|
con un tamaño inicial de lote diferente</title>
|
|
<para>
|
|
Encontrar todos los valores distintos de una clave.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$m = new MongoClient;
|
|
$db = $m->test;
|
|
$people = $db->people;
|
|
$people->drop();
|
|
|
|
/* Insert some sample data */
|
|
$people->insert(array("name" => "Joe", "points" => 4));
|
|
$people->insert(array("name" => "Molly", "points" => 43));
|
|
$people->insert(array("name" => "Sally", "points" => 22));
|
|
$people->insert(array("name" => "Joe", "points" => 22));
|
|
$people->insert(array("name" => "Molly", "points" => 87));
|
|
|
|
/* Run the command cursor */
|
|
$ages = $people->aggregateCursor(
|
|
[
|
|
[ '$group' => [ '_id' => '$name', 'points' => [ '$sum' => '$points' ] ] ],
|
|
[ '$sort' => [ 'points' => -1 ] ],
|
|
],
|
|
[ "cursor" => [ "batchSize" => 4 ] ]
|
|
);
|
|
|
|
foreach ($ages as $person) {
|
|
echo "{$person['_id']}: {$person['points']}\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
Molly: 130
|
|
Joe: 26
|
|
Sally: 22
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><methodname>MongoDB::command</methodname></member>
|
|
<member><classname>MongoCommandCursor</classname></member>
|
|
<member><methodname>MongoCommandCursor::batchSize</methodname></member>
|
|
<member><methodname>MongoCollection::aggregate</methodname></member>
|
|
<member>El <link xlink:href="&url.mongodb.docs.aggregation;">marco de acumulación</link> de MongoDB</member>
|
|
</simplelist>
|
|
</para>
|
|
</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
|
|
-->
|