Geen cache-versie.


Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher une fonction PHP

MongoCollection: : aggregateCursor

(PECL mongo >=1.5.0)

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

Description

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.

Note: 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.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Parameters

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 on the server (does not include idle time). If the operation is not completed by the server within the timeout period, a MongoExecutionTimeoutException will be thrown.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Return Values

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.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Examples

Example #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";
}

?>

The above example will output something similar to:


Molly: 130
Joe: 26
Sally: 22

Example #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";
}

?>

The above example will output something similar to:


Molly: 130
Joe: 26
Sally: 22

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

See Also

Zoek een PHP-functie

Vertaling niet beschikbaar

De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.

Als je de moed voelt, kun je je vertaling aanbieden ;-)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-mongocollection.aggregatecursor.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : http://php.net

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut