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 = [], bool $hydrate = true, bool $refresh = false, array $primers = [], bool $readOnly = false)

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

__clone()

No description

debug(string|null $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()

No description

getIterator()

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

getQuery()

Return the query structure.

array|object|null
getSingleResult()

Execute the query and return the first result.

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.

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 = [], bool $hydrate = true, bool $refresh = false, array $primers = [], bool $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
bool $hydrate
bool $refresh
array $primers
bool $readOnly

__clone()

debug(string|null $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|null $name

Iterator|int|string|array execute()

Execute the query and returns the results.

Return Value

Iterator|int|string|array

Exceptions

MongoDBException

getClass()

Gets the ClassMetadata instance.

getDocumentManager()

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.

Exceptions

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

See also

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

getQuery()

Return the query structure.

array|object|null getSingleResult()

Execute the query and return the first result.

Return Value

array|object|null

getType()

Return the query type.

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

toArray()

Execute the query and return its results as an 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