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

The MongoCursor class

(PECL mongo >=0.9.0)

Einführung

A cursor is used to iterate through the results of a database query. For example, to query the database and see all results, you could do:

Beispiel #1 MongoCursor basic usage

<?php

$cursor 
$collection->find();
var_dump(iterator_to_array($cursor));

?>

You don't generally create cursors using the MongoCursor constructor, you get a new cursor by calling MongoCollection::find() (as shown above).

Suppose that, in the example above, $collection was a 50GB collection. We certainly wouldn't want to load that into memory all at once, which is what a cursor is for: allowing the client to access the collection in dribs and drabs.

If we have a large result set, we can iterate through it, loading a few megabytes of results into memory at a time. For example, we could do:

Beispiel #2 Iterating over MongoCursor

<?php

$cursor 
$collection->find();

foreach (
$cursor as $doc) {
    
// do something to each document
}

?>
This will go through each document in the collection, loading and garbage collecting documents as needed.

Note that this means that a cursor does not "contain" the database results, it just manages them. Thus, if you print a cursor (with, say, var_dump() or print_r()), you'll just get the cursor object, not your documents. To get the documents themselves, you can use one of the methods shown above.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Cursor Stages

A MongoCursor has two "life stages": pre- and post- query. When a cursor is created, it has not yet contacted the database, so it is in its pre-query state. In this state, the client can further specify what they want the query to do, including adding limits, skips, sorts, and more advanced options.

When the client attempts to get a result (by calling MongoCursor::next(), directly or indirectly), the cursor moves into the post-query stage. At this point, the query has been executed by the database and cannot be modified anymore.

Beispiel #3 Adding options to MongoCursor

<?php

$cursor 
$collection->find()->limit(10);

// database has not yet been queried, so more search options can be added
$cursor $cursor->sort(array("a" => 1));

var_dump($cursor->getNext());
// now database has been queried and more options cannot be added

// so this will throw an exception:
$cursor->skip(4);
?>

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Klassenbeschreibung

MongoCursor implements MongoCursorInterface , Iterator {
/* Static Fields */
static boolean $slaveOkay = FALSE ;
static integer $timeout = 30000 ;
/* Methoden */
public addOption ( string $key , mixed $value ) : MongoCursor
public awaitData ([ bool $wait = TRUE ] ) : MongoCursor
public batchSize ( int $batchSize ) : MongoCursor
public __construct ( MongoClient $connection , string $ns [, array $query = array() [, array $fields = array() ]] )
public count ([ bool $foundOnly = FALSE ] ) : int
public current ( void ) : array
public dead ( void ) : bool
protected doQuery ( void ) : void
public explain ( void ) : array
public fields ( array $f ) : MongoCursor
public getNext ( void ) : array
public getReadPreference ( void ) : array
public hasNext ( void ) : bool
public hint ( mixed $index ) : MongoCursor
public immortal ([ bool $liveForever = TRUE ] ) : MongoCursor
public info ( void ) : array
public key ( void ) : string|int
public limit ( int $num ) : MongoCursor
public maxTimeMS ( int $ms ) : MongoCursor
public next ( void ) : array
public partial ([ bool $okay = TRUE ] ) : MongoCursor
public reset ( void ) : void
public rewind ( void ) : void
public setFlag ( int $flag [, bool $set = TRUE ] ) : MongoCursor
public setReadPreference ( string $read_preference [, array $tags ] ) : MongoCursor
public skip ( int $num ) : MongoCursor
public slaveOkay ([ bool $okay = TRUE ] ) : MongoCursor
public snapshot ( void ) : MongoCursor
public sort ( array $fields ) : MongoCursor
public tailable ([ bool $tail = TRUE ] ) : MongoCursor
public timeout ( int $ms ) : MongoCursor
public valid ( void ) : bool
}

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Static Variables

slaveOkay

If the query should have the "slaveOkay" flag set, which allows reads on the secondary (secondaries are, by default, just for backup and not queried). Can be overridden with MongoCursor::slaveOkay().

This functionality is deprecated. Please use Read Preferences instead.

timeout

Set timeout in milliseconds for all database responses. Use -1 to wait forever. Can be overridden with MongoCursor::timeout(). This does not cause the MongoDB server to cancel the operation; it only instructs the driver to stop waiting for a response and throw a MongoCursorTimeoutException after a set time.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Inhaltsverzeichnis

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-class.mongocursor.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