Since: 1.6.0

interface CursorInterface implements Iterator (View source)

This interface is implemented by MongoDB\Driver\Cursor but may also be used for type-hinting and userland classes.

Methods

mixed
current()

Return the current element

void
next()

Move forward to next element

from  Iterator
mixed
key()

Return the key of the current element

bool
valid()

Checks if current position is valid

from  Iterator
void
rewind()

Rewind the Iterator to the first element

from  Iterator
getId()

Returns the cursor ID associated with this cursor. A cursor ID uniquely identifies the cursor on the server.

getServer()

Returns the MongoDB\Driver\Server associated with this cursor.

bool
isDead()

Checks whether the cursor may have additional results available to read.

void
setTypeMap(array $typemap)

Sets a type map to use for BSON unserialization

array
toArray()

Iterates the cursor and returns its results in an array.

Details

mixed current()

Return the current element

Return Value

mixed

Can return any type.

void next()

Move forward to next element

Return Value

void

Any returned value is ignored.

mixed key()

Return the key of the current element

Return Value

mixed

TKey on success, or null on failure.

bool valid()

Checks if current position is valid

Return Value

bool

The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.

void rewind()

Rewind the Iterator to the first element

Return Value

void

Any returned value is ignored.

Int64 getId()

Returns the cursor ID associated with this cursor. A cursor ID uniquely identifies the cursor on the server.

Return Value

Int64

Returns the cursor ID for this cursor.

Exceptions

InvalidArgumentException

Server getServer()

Returns the MongoDB\Driver\Server associated with this cursor.

This is the server that executed the MongoDB\Driver\Query or MongoDB\Driver\Command.

Return Value

Server

Returns the MongoDB\Driver\Server associated with this cursor.

Exceptions

InvalidArgumentException

bool isDead()

Checks whether the cursor may have additional results available to read.

Return Value

bool

Returns TRUE if additional results are not available, and FALSE otherwise.

Exceptions

InvalidArgumentException

void setTypeMap(array $typemap)

Sets a type map to use for BSON unserialization

Parameters

array $typemap

Type map configuration.

Return Value

void

Exceptions

InvalidArgumentException

array toArray()

Iterates the cursor and returns its results in an array.

MongoDB\Driver\CursorInterface::setTypeMap() may be used to control how documents are unserialized into PHP values.

Return Value

array

Returns an array containing all results for this cursor.

Exceptions

InvalidArgumentException