class Query implements IteratorAggregate (View source)

ODM Query wraps the raw Doctrine MongoDB queries to add additional functionality and to hydrate the raw arrays of data to Doctrine document objects.

Constants

TYPE_FIND

TYPE_FIND_AND_UPDATE

TYPE_FIND_AND_REMOVE

TYPE_INSERT

TYPE_UPDATE

TYPE_REMOVE

TYPE_GROUP

TYPE_MAP_REDUCE

TYPE_DISTINCT

TYPE_COUNT

TYPE_GEO_LOCATION

HINT_REFRESH

HINT_READ_PREFERENCE

HINT_READ_ONLY

Properties

protected Collection $collection The Collection instance.

Methods

__construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = [], array $options = [], $hydrate = true, $refresh = false, array $primers = [], $readOnly = false)

Please note that $requireIndexes was deprecated in 1.2 and will be removed in 2.0

__clone()

No description

mixed
debug(string $name = null)

Return an array of information about the query structure for debugging.

Iterator|int|string|array
execute()

Execute the query and returns the results.

getClass()

Gets the ClassMetadata instance.

getDocumentManager()

Gets the DocumentManager instance.

getIterator()

Execute the query and return its result, which must be an Iterator.

array
getQuery()

Return the query structure.

array|object|null
getSingleResult()

Execute the query and return the first result.

int
getType()

Return the query type.

setHydrate(bool $hydrate)

Sets whether or not to hydrate the documents to objects.

setReadOnly(bool $readOnly)

Set whether documents should be registered in UnitOfWork. If document would already be managed it will be left intact and new instance returned.

setRefresh(bool $refresh)

Set whether to refresh hydrated documents that are already in the identity map.

array
toArray()

Execute the query and return its results as an array.

Iterator|string|int|array
runQuery()

Execute the query and return its result.

Details

__construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = [], array $options = [], $hydrate = true, $refresh = false, array $primers = [], $readOnly = false)

Please note that $requireIndexes was deprecated in 1.2 and will be removed in 2.0

Parameters

DocumentManager $dm
ClassMetadata $class
Collection $collection
array $query
array $options
$hydrate
$refresh
array $primers
$readOnly

__clone()

mixed debug(string $name = null)

Return an array of information about the query structure for debugging.

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.

Parameters

string $name

Return Value

mixed

Iterator|int|string|array execute()

Execute the query and returns the results.

Return Value

Iterator|int|string|array

Exceptions

MongoDBException

ClassMetadata getClass()

Gets the ClassMetadata instance.

Return Value

ClassMetadata $class

DocumentManager getDocumentManager()

Gets the DocumentManager instance.

Return Value

DocumentManager $dm

Iterator getIterator()

Execute the query and return its result, which must be an Iterator.

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.

Return Value

Iterator

Exceptions

BadMethodCallException If the query type would not return an Iterator.
UnexpectedValueException If the query did not return an Iterator.

See also

http://php.net/manual/en/iteratoraggregate.getiterator.php

array getQuery()

Return the query structure.

Return Value

array

array|object|null getSingleResult()

Execute the query and return the first result.

Return Value

array|object|null

int getType()

Return the query type.

Return Value

int

setHydrate(bool $hydrate)

Sets whether or not to hydrate the documents to objects.

Parameters

bool $hydrate

setReadOnly(bool $readOnly)

Set whether documents should be registered in UnitOfWork. If document would already be managed it will be left intact and new instance returned.

This option has no effect if hydration is disabled.

Parameters

bool $readOnly

setRefresh(bool $refresh)

Set whether to refresh hydrated documents that are already in the identity map.

This option has no effect if hydration is disabled.

Parameters

bool $refresh

array toArray()

Execute the query and return its results as an array.

Return Value

array

See also

IteratorAggregate::toArray()

Iterator|string|int|array runQuery()

Execute the query and return its result.

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 an Iterator.

Return Value

Iterator|string|int|array