class Cursor implements CursorInterface (View source)

Wrapper for the PHP MongoCursor class.

Properties

protected Collection $collection The Collection instance used for recreating this cursor.
protected MongoCursor $mongoCursor The MongoCursor instance being wrapped.
protected integer $numRetries Number of times to retry queries.
protected boolean $useIdentifierKeys Whether to use the document's "_id" value as its iteration key.
protected $query
protected $fields
protected $hint
protected $immortal
protected $options
protected $batchSize
protected $limit
protected $maxTimeMS
protected $readPreference
protected $readPreferenceTags
protected $skip
protected $slaveOkay
protected $snapshot
protected $sort
protected $tailable
protected $timeout

Methods

__construct(Collection $collection, MongoCursor $mongoCursor, array $query = [], array $fields = [], integer $numRetries = 0)

Constructor.

$this
addOption(string $key, mixed $value)

Wrapper method for MongoCursor::addOption().

$this
batchSize(integer $num)

Wrapper method for MongoCursor::batchSize().

integer
count(boolean $foundOnly = false)

Wrapper method for MongoCursor::count().

array|null
current()

Wrapper method for MongoCursor::current().

boolean
dead()

Wrapper method for MongoCursor::dead().

array
explain()

Wrapper method for MongoCursor::explain().

$this
fields(array $f)

Wrapper method for MongoCursor::fields().

getCollection()

Return the collection for this cursor.

getConnection() deprecated

Return the connection for this cursor.

array
getFields()

Return the selected fields (projection).

MongoCursor
getMongoCursor()

Returns the MongoCursor instance being wrapped.

array|null
getNext()

Wrapper method for MongoCursor::getNext().

array
getQuery()

Return the query criteria.

array
getReadPreference()

Wrapper method for MongoCursor::getReadPreference().

$this
setReadPreference(string $readPreference, array $tags = null)

Set the read preference.

array|object|null
getSingleResult()

Reset the cursor and return its first result.

boolean
getUseIdentifierKeys()

Return whether the document's "_id" value is used as its iteration key.

$this
setUseIdentifierKeys(boolean $useIdentifierKeys)

Set whether to use the document's "_id" value as its iteration key.

boolean
hasNext()

Wrapper method for MongoCursor::hasNext().

$this
hint(array|string $keyPattern)

Wrapper method for MongoCursor::hint().

$this
immortal(boolean $liveForever = true)

Wrapper method for MongoCursor::immortal().

array
info()

Wrapper method for MongoCursor::info().

mixed
key()

Wrapper method for MongoCursor::key().

$this
limit(integer $num)

Wrapper method for MongoCursor::limit().

$this
maxTimeMS(integer $ms)

Wrapper method for MongoCursor::maxTimeMS().

next()

Wrapper method for MongoCursor::next().

recreate()

Recreates the internal MongoCursor.

reset()

Wrapper method for MongoCursor::reset().

rewind()

Wrapper method for MongoCursor::rewind().

setMongoCursorSlaveOkay(boolean $ok)

Set whether secondary read queries are allowed for this cursor.

$this
skip(integer $num)

Wrapper method for MongoCursor::skip().

$this
slaveOkay(boolean $ok = true)

Wrapper method for MongoCursor::slaveOkay().

$this
snapshot()

Wrapper method for MongoCursor::snapshot().

$this
sort(array $fields)

Wrapper method for MongoCursor::sort().

$this
tailable(boolean $tail = true)

Wrapper method for MongoCursor::tailable().

$this
timeout(integer $ms)

Wrapper method for MongoCursor::timeout().

array
toArray(boolean $useIdentifierKeys = null)

Return the cursor's results as an array.

boolean
valid()

Wrapper method for MongoCursor::valid().

mixed
retry(Closure $retry, boolean $recreate = false)

Conditionally retry a closure if it yields an exception.

Details

__construct(Collection $collection, MongoCursor $mongoCursor, array $query = [], array $fields = [], integer $numRetries = 0)

Constructor.

The wrapped MongoCursor instance may change if the cursor is recreated.

Parameters

Collection $collection Collection used to create this Cursor
MongoCursor $mongoCursor MongoCursor instance being wrapped
array $query Query criteria
array $fields Selected fields (projection)
integer $numRetries Number of times to retry queries

$this addOption(string $key, mixed $value)

Wrapper method for MongoCursor::addOption().

Parameters

string $key
mixed $value

Return Value

$this

See also

http://php.net/manual/en/mongocursor.addoption.php

$this batchSize(integer $num)

Wrapper method for MongoCursor::batchSize().

Parameters

integer $num

Return Value

$this

See also

http://php.net/manual/en/mongocursor.batchsize.php

integer count(boolean $foundOnly = false)

Wrapper method for MongoCursor::count().

Parameters

boolean $foundOnly

Return Value

integer

See also

http://php.net/manual/en/countable.count.php
http://php.net/manual/en/mongocursor.count.php

array|null current()

Wrapper method for MongoCursor::current().

boolean dead()

Wrapper method for MongoCursor::dead().

Return Value

boolean

See also

http://php.net/manual/en/mongocursor.dead.php

array explain()

Wrapper method for MongoCursor::explain().

$this fields(array $f)

Wrapper method for MongoCursor::fields().

Parameters

array $f Fields to return (or not return).

Return Value

$this

See also

http://php.net/manual/en/mongocursor.fields.php

Collection getCollection()

Return the collection for this cursor.

Return Value

Collection

Connection getConnection() deprecated

deprecated 1.1 Will be removed for 2.0

Return the connection for this cursor.

Return Value

Connection

array getFields()

Return the selected fields (projection).

Return Value

array

MongoCursor getMongoCursor()

Returns the MongoCursor instance being wrapped.

Return Value

MongoCursor

array|null getNext()

Wrapper method for MongoCursor::getNext().

Return Value

array|null

See also

http://php.net/manual/en/mongocursor.getnext.php

array getQuery()

Return the query criteria.

Return Value

array

array getReadPreference()

Wrapper method for MongoCursor::getReadPreference().

$this setReadPreference(string $readPreference, array $tags = null)

Set the read preference.

Parameters

string $readPreference
array $tags

Return Value

$this

See also

http://php.net/manual/en/mongocursor.setreadpreference.php

array|object|null getSingleResult()

Reset the cursor and return its first result.

The cursor will be reset both before and after the single result is fetched. The original cursor limit (if any) will remain in place.

Return Value

array|object|null

See also

Iterator::getSingleResult

boolean getUseIdentifierKeys()

Return whether the document's "_id" value is used as its iteration key.

Return Value

boolean

$this setUseIdentifierKeys(boolean $useIdentifierKeys)

Set whether to use the document's "_id" value as its iteration key.

Parameters

boolean $useIdentifierKeys

Return Value

$this

boolean hasNext()

Wrapper method for MongoCursor::hasNext().

Return Value

boolean

See also

http://php.net/manual/en/mongocursor.hasnext.php

$this hint(array|string $keyPattern)

Wrapper method for MongoCursor::hint().

Parameters

array|string $keyPattern

Return Value

$this

See also

http://php.net/manual/en/mongocursor.hint.php

$this immortal(boolean $liveForever = true)

Wrapper method for MongoCursor::immortal().

Parameters

boolean $liveForever

Return Value

$this

See also

http://php.net/manual/en/mongocursor.immortal.php

array info()

Wrapper method for MongoCursor::info().

Return Value

array

See also

http://php.net/manual/en/mongocursor.info.php

mixed key()

Wrapper method for MongoCursor::key().

$this limit(integer $num)

Wrapper method for MongoCursor::limit().

Parameters

integer $num

Return Value

$this

See also

http://php.net/manual/en/mongocursor.limit.php

$this maxTimeMS(integer $ms)

Wrapper method for MongoCursor::maxTimeMS().

Parameters

integer $ms

Return Value

$this

See also

http://php.net/manual/en/mongocursor.maxtimems.php

recreate()

Recreates the internal MongoCursor.

reset()

rewind()

setMongoCursorSlaveOkay(boolean $ok)

Set whether secondary read queries are allowed for this cursor.

This method wraps setSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method either wraps setReadPreference() method and specifies SECONDARY_PREFERRED or does nothing, depending on whether setReadPreference() exists.

Parameters

boolean $ok

$this skip(integer $num)

Wrapper method for MongoCursor::skip().

Parameters

integer $num

Return Value

$this

See also

http://php.net/manual/en/mongocursor.skip.php

$this slaveOkay(boolean $ok = true)

Wrapper method for MongoCursor::slaveOkay().

Parameters

boolean $ok

Return Value

$this

See also

http://php.net/manual/en/mongocursor.slaveokay.php

$this snapshot()

Wrapper method for MongoCursor::snapshot().

$this sort(array $fields)

Wrapper method for MongoCursor::sort().

Parameters

array $fields

Return Value

$this

See also

http://php.net/manual/en/mongocursor.sort.php

$this tailable(boolean $tail = true)

Wrapper method for MongoCursor::tailable().

Parameters

boolean $tail

Return Value

$this

See also

http://php.net/manual/en/mongocursor.tailable.php

$this timeout(integer $ms)

Wrapper method for MongoCursor::timeout().

Parameters

integer $ms

Return Value

$this

See also

http://php.net/manual/en/mongocursor.timeout.php

array toArray(boolean $useIdentifierKeys = null)

Return the cursor's results as an array.

Parameters

boolean $useIdentifierKeys Deprecated since 1.2; will be removed in 2.0

Return Value

array

See also

Iterator::toArray

boolean valid()

Wrapper method for MongoCursor::valid().

protected mixed retry(Closure $retry, boolean $recreate = false)

Conditionally retry a closure if it yields an exception.

If the closure does not return successfully within the configured number of retries, its first exception will be thrown.

The $recreate parameter may be used to recreate the MongoCursor between retry attempts.

Parameters

Closure $retry
boolean $recreate

Return Value

mixed