PHP Class MongoCursor

Inheritance: implements Iterator
Datei anzeigen Open project: alcaeus/mongo-php-adapter Class Usage Examples

Public Properties

Property Type Description
$slaveOkay boolean
$timeout integer

Protected Properties

Property Type Description
$allowPartialResults
$awaitData
$flags
$hint
$limit
$maxTimeMS
$noCursorTimeout
$optionNames array
$options
$projection array
$query array
$skip
$snapshot
$sort
$tailable

Public Methods

Method Description
__construct ( MongoClient $connection, string $ns, array $query = [], array $fields = [] ) Create a new cursor
__sleep ( ) : array
addOption ( string $key, mixed $value ) : MongoCursor Adds a top-level key/value pair to a query
awaitData ( boolean $wait = true ) : MongoCursor (PECL mongo >= 1.2.11)
Sets whether this cursor will wait for a while for a tailable cursor to return more data
count ( boolean $foundOnly = false ) : integer Counts the number of results for this query
explain ( ) : array Return an explanation of the query, often useful for optimization and debugging
fields ( array $f ) : MongoCursor Sets the fields for a query
getNext ( ) : array Advances the cursor to the next result, and returns that result
hasNext ( ) : boolean Checks if there are any more elements in this cursor
hint ( array | string $keyPattern ) : MongoCursor Gives the database a hint about the query
immortal ( boolean $liveForever = true ) : MongoCursor Sets whether this cursor will timeout
limit ( integer $num ) : MongoCursor Limits the number of results returned
maxTimeMS ( integer $ms )
partial ( boolean $okay = true ) : MongoCursor
reset ( ) : void Clears the cursor
setFlag ( integer $flag, boolean $set = true ) : MongoCursor
skip ( integer $num ) : MongoCursor Skips a number of results
slaveOkay ( boolean $okay = true ) : MongoCursor Sets whether this query can be done on a slave This method will override the static class variable slaveOkay.
snapshot ( ) : MongoCursor Use snapshot mode for the query
sort ( array $fields ) : MongoCursor Sorts the results by given fields
tailable ( boolean $tail = true ) : MongoCursor Sets whether this cursor will be left open after fetching the last results

Protected Methods

Method Description
convertCursorType ( ) : integer | null
convertModifiers ( ) : array
convertProjection ( ) : array
doQuery ( ) : void Execute the query
ensureCursor ( ) : MongoDB\Driver\Cursor
getCursorInfo ( ) : array
wrapTraversable ( Traversable $traversable ) : Generator

Method Details

__construct() public method

Create a new cursor
public __construct ( MongoClient $connection, string $ns, array $query = [], array $fields = [] )
$connection MongoClient Database connection.
$ns string Full name of database and collection.
$query array Database query.
$fields array Fields to return.

__sleep() public method

public __sleep ( ) : array
return array

addOption() public method

Adds a top-level key/value pair to a query
public addOption ( string $key, mixed $value ) : MongoCursor
$key string Fieldname to add.
$value mixed Value to add.
return MongoCursor Returns this cursor

awaitData() public method

(PECL mongo >= 1.2.11)
Sets whether this cursor will wait for a while for a tailable cursor to return more data
public awaitData ( boolean $wait = true ) : MongoCursor
$wait boolean [optional]

If the cursor should wait for more data to become available.

return MongoCursor Returns this cursor.

convertCursorType() protected method

protected convertCursorType ( ) : integer | null
return integer | null

convertModifiers() protected method

protected convertModifiers ( ) : array
return array

convertProjection() protected method

protected convertProjection ( ) : array
return array

count() public method

Counts the number of results for this query
public count ( boolean $foundOnly = false ) : integer
$foundOnly boolean Send cursor limit and skip information to the count function, if applicable.
return integer The number of documents returned by this cursor's query.

doQuery() protected method

Execute the query
protected doQuery ( ) : void
return void

ensureCursor() protected method

protected ensureCursor ( ) : MongoDB\Driver\Cursor
return MongoDB\Driver\Cursor

explain() public method

Return an explanation of the query, often useful for optimization and debugging
public explain ( ) : array
return array Returns an explanation of the query.

fields() public method

Sets the fields for a query
public fields ( array $f ) : MongoCursor
$f array Fields to return (or not return).
return MongoCursor

getCursorInfo() protected method

protected getCursorInfo ( ) : array
return array

getNext() public method

Advances the cursor to the next result, and returns that result
public getNext ( ) : array
return array Returns the next object

hasNext() public method

Checks if there are any more elements in this cursor
public hasNext ( ) : boolean
return boolean Returns true if there is another element

hint() public method

Gives the database a hint about the query
public hint ( array | string $keyPattern ) : MongoCursor
$keyPattern array | string Indexes to use for the query.
return MongoCursor Returns this cursor

immortal() public method

Sets whether this cursor will timeout
public immortal ( boolean $liveForever = true ) : MongoCursor
$liveForever boolean If the cursor should be immortal.
return MongoCursor Returns this cursor

limit() public method

Limits the number of results returned
public limit ( integer $num ) : MongoCursor
$num integer The number of results to return.
return MongoCursor Returns this cursor

maxTimeMS() public method

public maxTimeMS ( integer $ms )
$ms integer

partial() public method

public partial ( boolean $okay = true ) : MongoCursor
$okay boolean [optional]

If receiving partial results is okay.

return MongoCursor Returns this cursor.

reset() public method

Clears the cursor
public reset ( ) : void
return void

setFlag() public method

public setFlag ( integer $flag, boolean $set = true ) : MongoCursor
$flag integer
$set boolean
return MongoCursor

skip() public method

Skips a number of results
public skip ( integer $num ) : MongoCursor
$num integer The number of results to skip.
return MongoCursor Returns this cursor

slaveOkay() public method

Sets whether this query can be done on a slave This method will override the static class variable slaveOkay.
public slaveOkay ( boolean $okay = true ) : MongoCursor
$okay boolean If it is okay to query the slave.
return MongoCursor Returns this cursor

snapshot() public method

Use snapshot mode for the query
public snapshot ( ) : MongoCursor
return MongoCursor Returns this cursor

sort() public method

Sorts the results by given fields
public sort ( array $fields ) : MongoCursor
$fields array An array of fields by which to sort. Each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort
return MongoCursor Returns the same cursor that this method was called on

tailable() public method

Sets whether this cursor will be left open after fetching the last results
public tailable ( boolean $tail = true ) : MongoCursor
$tail boolean If the cursor should be tailable.
return MongoCursor Returns this cursor

wrapTraversable() protected method

protected wrapTraversable ( Traversable $traversable ) : Generator
$traversable Traversable
return Generator

Property Details

$allowPartialResults protected_oe property

protected $allowPartialResults

$awaitData protected_oe property

protected $awaitData

$flags protected_oe property

protected $flags

$hint protected_oe property

protected $hint

$limit protected_oe property

protected $limit

$maxTimeMS protected_oe property

protected $maxTimeMS

$noCursorTimeout protected_oe property

protected $noCursorTimeout

$optionNames protected_oe property

protected array $optionNames
return array

$options protected_oe property

protected $options

$projection protected_oe property

protected array $projection
return array

$query protected_oe property

protected array $query
return array

$skip protected_oe property

protected $skip

$slaveOkay public_oe static_oe property

public static bool $slaveOkay
return boolean

$snapshot protected_oe property

protected $snapshot

$sort protected_oe property

protected $sort

$tailable protected_oe property

protected $tailable

$timeout public_oe static_oe property

public static int $timeout
return integer