PHP Class Doctrine\MongoDB\Query\Query

Since: 1.0
Author: Jonathan H. Wage ([email protected])
Author: Bulat Shakirzyanov ([email protected])
Inheritance: implements Doctrine\MongoDB\IteratorAggregate
Show file Open project: doctrine/mongodb Class Usage Examples

Protected Properties

Property Type Description
$collection Doctrine\MongoDB\Collection The Collection instance.
$iterator Doctrine\MongoDB\Iterator
$options array Query options
$query array Query structure generated by the Builder class.

Public Methods

Method Description
__construct ( Doctrine\MongoDB\Collection $collection, array $query, array $options ) Constructor.
count ( boolean $foundOnly = false ) : integer Count the number of results for this query.
debug ( string $name = null ) : mixed Return an array of information about the query structure for debugging.
execute ( ) : mixed Execute the query and return its result.
getIterator ( ) : Doctrine\MongoDB\Iterator Execute the query and return its result, which must be an Iterator.
getQuery ( ) : array Return the query structure.
getSingleResult ( ) : array | object | null Execute the query and return the first result.
getType ( ) : integer Return the query type.
iterate ( ) : Doctrine\MongoDB\Iterator Alias of {@link Query::getIterator()}.
toArray ( ) : array Execute the query and return its results as an array.

Protected Methods

Method Description
prepareCursor ( Doctrine\MongoDB\Cursor $cursor ) : Doctrine\MongoDB\CursorInterface Prepare the Cursor returned by {@link Query::execute()}.

Private Methods

Method Description
getQueryOptions ( ) : array Returns an array containing the specified keys and their values from the query array, provided they exist and are not null.
renameQueryOptions ( array $options, array $rename ) : array Returns an array with its keys renamed based on the translation map.
withReadPreference ( Doctrine\MongoDB\Database | Doctrine\MongoDB\Collection $object, Closure $closure ) : mixed Executes a closure with a temporary read preference on a database or collection.

Method Details

__construct() public method

Constructor.
public __construct ( Doctrine\MongoDB\Collection $collection, array $query, array $options )
$collection Doctrine\MongoDB\Collection
$query array
$options array

count() public method

If the query resulted in a Cursor, the $foundOnly parameter will ignore limit/skip values if false (the default). If the Query resulted in an EagerCursor or ArrayIterator, the $foundOnly parameter has no effect.
public count ( boolean $foundOnly = false ) : integer
$foundOnly boolean
return integer

debug() public method

The $name parameter may be used to return a specific key from the internal $query array property. If omitted, the entire array will be returned.
public debug ( string $name = null ) : mixed
$name string
return mixed

execute() public method

The return value will vary based on the query type. Commands with results (e.g. aggregate, inline mapReduce) may return an ArrayIterator. Other commands and operations may return a status array or a boolean, depending on the driver's write concern. Queries and some mapReduce commands will return a CursorInterface.
public execute ( ) : mixed
return mixed

getIterator() public method

If the query type is not expected to return an Iterator, BadMethodCallException will be thrown before executing the query. Otherwise, the query will be executed and UnexpectedValueException will be thrown if {@link Query::execute()} does not return an Iterator.
See also: http://php.net/manual/en/iteratoraggregate.getiterator.php
public getIterator ( ) : Doctrine\MongoDB\Iterator
return Doctrine\MongoDB\Iterator

getQuery() public method

Return the query structure.
public getQuery ( ) : array
return array

getSingleResult() public method

Execute the query and return the first result.
See also: IteratorAggregate::getSingleResult()
public getSingleResult ( ) : array | object | null
return array | object | null

getType() public method

Return the query type.
public getType ( ) : integer
return integer

iterate() public method

Alias of {@link Query::getIterator()}.
Deprecation: 1.1 Use {@link Query::getIterator()}; will be removed for 2.0
public iterate ( ) : Doctrine\MongoDB\Iterator
return Doctrine\MongoDB\Iterator

prepareCursor() protected method

This method will apply cursor options present in the query structure array. The Cursor may also be wrapped with an EagerCursor.
protected prepareCursor ( Doctrine\MongoDB\Cursor $cursor ) : Doctrine\MongoDB\CursorInterface
$cursor Doctrine\MongoDB\Cursor
return Doctrine\MongoDB\CursorInterface

toArray() public method

Execute the query and return its results as an array.
See also: IteratorAggregate::toArray()
public toArray ( ) : array
return array

Property Details

$collection protected property

The Collection instance.
protected Collection,Doctrine\MongoDB $collection
return Doctrine\MongoDB\Collection

$iterator protected property

protected Iterator,Doctrine\MongoDB $iterator
return Doctrine\MongoDB\Iterator

$options protected property

Query options
protected array $options
return array

$query protected property

Query structure generated by the Builder class.
protected array $query
return array