Keine Cache-Version


Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Rechercher une fonction PHP

MongoCollection: : aggregateCursor

(PECL mongo >=1.5.0)

MongoCollection::aggregateCursorExecute an aggregation pipeline command and retrieve results through a cursor

Beschreibung

public MongoCollection::aggregateCursor ( array $command [, array $options ] ) : MongoCommandCursor

With this method you can execute Aggregation Framework pipelines and retrieve the results through a cursor, instead of getting just one document back as you would with MongoCollection::aggregate(). This method returns a MongoCommandCursor object. This cursor object implements the Iterator interface just like the MongoCursor objects that are returned by the MongoCollection::find() method.

Hinweis: The resulting MongoCommandCursor will inherit this collection's read preference. MongoCommandCursor::setReadPreference() may be used to change the read preference before iterating on the cursor.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Parameter-Liste

pipeline

The Aggregation Framework pipeline to execute.

options

Options for the aggregation command. Valid options include:

  • "allowDiskUse"

    Allow aggregation stages to write to temporary files

  • "cursor"

    It is possible to configure how many initial documents the server should return with the first result set. The default initial batch size is 101. You can change it by adding the batchSize option:

    <?php
    $collection
    ->aggregateCursor
        
    $pipeline,
        [ 
    "cursor" => [ "batchSize" => ] ]
    );

    This option only configures the size of the first batch. To configure the size of future batches, please use the MongoCommandCursor::batchSize() method on the returned MongoCommandCursor object.

  • "explain"

    Return information on the processing of the pipeline. This option may cause the command to return a result document that is unsuitable for constructing a MongoCommandCursor. If you need to use this option, you should consider using MongoCollection::aggregate().

  • "maxTimeMS"

    Specifies a cumulative time limit in milliseconds for processing the operation (does not include idle time). If the operation is not completed within the timeout period, a MongoExecutionTimeoutException will be thrown.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Rückgabewerte

Returns a MongoCommandCursor object. Because this implements the Iterator interface you can iterate over each of the results as returned by the command query. The MongoCommandCursor also implements the MongoCursorInterface interface which adds the MongoCommandCursor::batchSize(), MongoCommandCursor::dead(), MongoCommandCursor::info() methods.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Beispiele

Beispiel #1 MongoCollection::aggregateCursor() example

Finding all of the distinct values for a key.

<?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' => -] ],
] );

foreach (
$ages as $person) {
    echo 
"{$person['_id']}{$person['points']}\n";
}

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:


Molly: 130
Joe: 26
Sally: 22

Beispiel #2 MongoCollection::aggregateCursor() example with different initial batch size

Finding all of the distinct values for a key.

<?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' => -] ],
    ],
    [ 
"cursor" => [ "batchSize" => ] ]
);

foreach (
$ages as $person) {
    echo 
"{$person['_id']}{$person['points']}\n";
}

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:


Molly: 130
Joe: 26
Sally: 22

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Siehe auch

Finde eine PHP-Funktion

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 30/01/2003, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/php-rf-mongocollection.aggregatecursor.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:fr Manuel PHP : http://php.net

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut