PHP Class Sokil\Mongo\Cursor

Inheritance: implements Iterator, implements Countable
Show file Open project: sokil/php-mongo Class Usage Examples

Public Methods

Method Description
__call ( $name, $arguments )
__construct ( Collection $collection, array $options = null )
asArray ( )
asObject ( )
byId ( string | MongoId $id ) : Cursor Filter by id
byIdList ( array $idList ) : Cursor Filter by list of \MongoId
copyToCollection ( type $targetCollectionName, type $targetDatabaseName = null ) Copy selected documents to another collection
count ( ) : integer Count documents in result without applying limit and offset
current ( )
explain ( )
expression ( ) : Expression Helper to create new expression
field ( string $field ) : Cursor Append field to accept list
fields ( array $fields ) : Cursor Return only specified fields
filter ( $handler )
findAll ( ) : array
findAndRemove ( ) : Document Get document instance and remove it from collection
findAndUpdate ( Operator $operator, boolean $upsert = false, boolean $returnUpdated = true ) : null | Document Find first document and update it
findOne ( ) : Document | array | null Find one document which correspond to expression
findRandom ( ) Get random document
getExpression ( ) : Expression Get query builder's expression
getHash ( ) Used to get hash that uniquely identifies current query
getIdList ( ) : array Gte list of \MongoId of current search query
getMongoQuery ( ) : array Get MongoDB query array
getOption ( string | integer $name, $default = null ) : mixed Get option
getReadPreference ( )
getResultSet ( ) : Sokil\Mongo\ResultSet Get result set of documents.
hint ( array | string $specification ) : Cursor Specify index to use
isDocumentPoolUsed ( )
isResultAsArray ( ) : boolean Check if result returned as array
key ( )
limit ( integer $limit, integer | null $offset = null ) : Cursor Limit result set to specified number of elements
limitedCount ( ) : integer Count documents in result with applying limit and offset
map ( $handler )
mixedToMongoIdList ( array $list ) : array Get list of MongoId objects from array of strings, MongoId's and Document's
moveToCollection ( type $targetCollectionName, type $targetDatabaseName = null ) Move selected documents to another collection.
next ( )
paginate ( integer $page, integer $itemsOnPage = 30 ) : Sokil\Mongo\Paginator Get paginator
pluck ( string $fieldName ) : array Return the values from a single field in the result set of documents
query ( Expression $expression ) : Cursor Merge expression
readNearest ( array $tags = null )
readPrimaryOnly ( )
readPrimaryPreferred ( array $tags = null )
readSecondaryOnly ( array $tags = null )
readSecondaryPreferred ( array $tags = null )
rewind ( )
setBatchSize ( integer $size ) : Cursor Specifies the number of documents to return in each batch of the response from the MongoDB instance.
setClientTimeout ( type $ms ) : Cursor Instructs the driver to stop waiting for a response and throw a MongoCursorTimeoutException after a set time, A timeout can be set at any time and will affect subsequent queries on the cursor, including fetching more results from the database.
setServerTimeout ( type $ms ) : Cursor Server-side timeout for a query, Specifies a cumulative time limit in milliseconds to be allowed by the server for processing operations on the cursor.
skip ( integer $skip ) : Cursor Skip defined number of documents
skipDocumentPool ( )
skipField ( string $field ) : Cursor Append field to skip list
skipFields ( array $fields ) : Cursor Return all fields except specified
slice ( string $field, integer $limit, integer $skip = null ) : Cursor Paginate list of sub-documents
sort ( array $sort ) : Cursor Sort result by specified keys and directions
useDocumentPool ( )
valid ( )

Private Methods

Method Description
getCursor ( ) : MongoCursor
pluckDotNoteted ( string $fieldName ) : array Pluck by dot-notated field name

Method Details

__call() public method

public __call ( $name, $arguments )

__construct() public method

public __construct ( Collection $collection, array $options = null )
$collection Collection
$options array

asArray() public method

public asArray ( )

asObject() public method

public asObject ( )

byId() public method

Filter by id
public byId ( string | MongoId $id ) : Cursor
$id string | MongoId id of document
return Cursor

byIdList() public method

Filter by list of \MongoId
public byIdList ( array $idList ) : Cursor
$idList array list of ids
return Cursor

copyToCollection() public method

Copy selected documents to another collection
public copyToCollection ( type $targetCollectionName, type $targetDatabaseName = null )
$targetCollectionName type
$targetDatabaseName type Target database name. If not specified - use current

count() public method

Count documents in result without applying limit and offset
public count ( ) : integer
return integer count

current() public method

public current ( )

explain() public method

public explain ( )

expression() public method

Helper to create new expression
public expression ( ) : Expression
return Expression

field() public method

Append field to accept list
public field ( string $field ) : Cursor
$field string field name
return Cursor

fields() public method

Return only specified fields
public fields ( array $fields ) : Cursor
$fields array
return Cursor

filter() public method

public filter ( $handler )

findAll() public method

public findAll ( ) : array
return array result of searching

findAndRemove() public method

Get document instance and remove it from collection
public findAndRemove ( ) : Document
return Document

findAndUpdate() public method

Find first document and update it
public findAndUpdate ( Operator $operator, boolean $upsert = false, boolean $returnUpdated = true ) : null | Document
$operator Operator operations with document to update
$upsert boolean if document not found - create
$returnUpdated boolean if true - return updated document
return null | Document

findOne() public method

Find one document which correspond to expression
public findOne ( ) : Document | array | null
return Document | array | null

findRandom() public method

Get random document
public findRandom ( )

getExpression() public method

Get query builder's expression
public getExpression ( ) : Expression
return Expression

getHash() public method

Used to get hash that uniquely identifies current query
public getHash ( )

getIdList() public method

Gte list of \MongoId of current search query
public getIdList ( ) : array
return array

getMongoQuery() public method

Get MongoDB query array
public getMongoQuery ( ) : array
return array

getOption() public method

Get option
public getOption ( string | integer $name, $default = null ) : mixed
$name string | integer
return mixed

getReadPreference() public method

public getReadPreference ( )

getResultSet() public method

Get result set of documents.
public getResultSet ( ) : Sokil\Mongo\ResultSet
return Sokil\Mongo\ResultSet

hint() public method

Specify index to use
public hint ( array | string $specification ) : Cursor
$specification array | string Specify the index either by the index name or by document
return Cursor

isDocumentPoolUsed() public method

public isDocumentPoolUsed ( )

isResultAsArray() public method

Check if result returned as array
public isResultAsArray ( ) : boolean
return boolean

key() public method

public key ( )

limit() public method

Limit result set to specified number of elements
public limit ( integer $limit, integer | null $offset = null ) : Cursor
$limit integer number of elements in result set
$offset integer | null number of elements to skip
return Cursor

limitedCount() public method

Count documents in result with applying limit and offset
public limitedCount ( ) : integer
return integer count

map() public method

public map ( $handler )

mixedToMongoIdList() public static method

Get list of MongoId objects from array of strings, MongoId's and Document's
public static mixedToMongoIdList ( array $list ) : array
$list array
return array list of \MongoId

moveToCollection() public method

Dociuments will be removed from source collection only after copying them to target collection.
public moveToCollection ( type $targetCollectionName, type $targetDatabaseName = null )
$targetCollectionName type
$targetDatabaseName type Target database name. If not specified - use current

next() public method

public next ( )

paginate() public method

Get paginator
public paginate ( integer $page, integer $itemsOnPage = 30 ) : Sokil\Mongo\Paginator
$page integer page number
$itemsOnPage integer number of items on page
return Sokil\Mongo\Paginator

pluck() public method

Return the values from a single field in the result set of documents
public pluck ( string $fieldName ) : array
$fieldName string
return array

query() public method

Merge expression
public query ( Expression $expression ) : Cursor
$expression Expression
return Cursor

readNearest() public method

public readNearest ( array $tags = null )
$tags array

readPrimaryOnly() public method

public readPrimaryOnly ( )

readPrimaryPreferred() public method

public readPrimaryPreferred ( array $tags = null )
$tags array

readSecondaryOnly() public method

public readSecondaryOnly ( array $tags = null )
$tags array

readSecondaryPreferred() public method

public readSecondaryPreferred ( array $tags = null )
$tags array

rewind() public method

public rewind ( )

setBatchSize() public method

Specifies the number of documents to return in each batch of the response from the MongoDB instance.
public setBatchSize ( integer $size ) : Cursor
$size integer number of documents
return Cursor

setClientTimeout() public method

Instructs the driver to stop waiting for a response and throw a MongoCursorTimeoutException after a set time, A timeout can be set at any time and will affect subsequent queries on the cursor, including fetching more results from the database.
public setClientTimeout ( type $ms ) : Cursor
$ms type
return Cursor

setServerTimeout() public method

Server-side timeout for a query, Specifies a cumulative time limit in milliseconds to be allowed by the server for processing operations on the cursor.
public setServerTimeout ( type $ms ) : Cursor
$ms type
return Cursor

skip() public method

Skip defined number of documents
public skip ( integer $skip ) : Cursor
$skip integer number of documents to skip
return Cursor

skipDocumentPool() public method

public skipDocumentPool ( )

skipField() public method

Append field to skip list
public skipField ( string $field ) : Cursor
$field string field name
return Cursor

skipFields() public method

Return all fields except specified
public skipFields ( array $fields ) : Cursor
$fields array
return Cursor

slice() public method

Paginate list of sub-documents
public slice ( string $field, integer $limit, integer $skip = null ) : Cursor
$field string
$limit integer
$skip integer
return Cursor

sort() public method

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. Each result is first sorted on the first field in the array, then (if it exists) on the second field in the array, etc. This means that the order of the fields in the fields array is important. See also the examples section.
public sort ( array $sort ) : Cursor
$sort array
return Cursor

useDocumentPool() public method

public useDocumentPool ( )

valid() public method

public valid ( )