final class Cursor implements CursorInterface, Iterator (View source)

The MongoDB\Driver\Cursor class encapsulates the results of a MongoDB command or query and may be returned by MongoDB\Driver\Manager::executeCommand() or MongoDB\Driver\Manager::executeQuery(), respectively.

Methods

__wakeup()

No description

mixed
current()

Returns the current element.

Int64
getId(bool $asInt64 = false)

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

getServer()

Returns the MongoDB\Driver\Server associated with this cursor. This is the server that executed the query or command.

bool
isDead()

Checks if a cursor is still alive

mixed
key()

Returns the current result's index within the cursor.

void
next()

Advances the cursor to the next result.

void
rewind()

Rewind the cursor to the first result.

void
setTypeMap(array $typemap)

Sets a type map to use for BSON unserialization

array
toArray()

Returns an array of all result documents for this cursor

bool
valid()

Checks if the current position in the cursor is valid.

Details

final __wakeup()

No description

mixed current()

Returns the current element.

Return Value

mixed

Can return any type.

final Int64 getId(bool $asInt64 = false)

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

Receiving a CursorId return type is deprecated and will be removed in 2.0.

Parameters

bool $asInt64

Pass true to receive the cursor as a MongoDB\BSON\Int64 instance

Return Value

Int64

Returns the cursor ID for this cursor.

Exceptions

InvalidArgumentException

final Server getServer()

Returns the MongoDB\Driver\Server associated with this cursor. This is the server that executed the query or command.

Return Value

Server

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

Exceptions

InvalidArgumentException

final bool isDead()

Checks if a cursor is still alive

Return Value

bool

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

Exceptions

InvalidArgumentException

mixed key()

Returns the current result's index within the cursor.

Return Value

mixed

TKey on success, or null on failure.

void next()

Advances the cursor to the next result.

Return Value

void

Any returned value is ignored.

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException

void rewind()

Rewind the cursor to the first result.

Return Value

void

Any returned value is ignored.

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
LogicException

final void setTypeMap(array $typemap)

Sets a type map to use for BSON unserialization

Parameters

array $typemap

Type map configuration.

Return Value

void

Exceptions

InvalidArgumentException

final array toArray()

Returns an array of all result documents for this cursor

Return Value

array

Returns an array containing all results for this cursor.

Exceptions

InvalidArgumentException

bool valid()

Checks if the current position in the cursor is valid.

Return Value

bool

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