class Query extends Query (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

HINT_REFRESH

HINT_SLAVE_OKAY

HINT_READ_PREFERENCE

HINT_READ_PREFERENCE_TAGS

HINT_READ_ONLY

Methods

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

Constructor.

getDocumentManager()

Gets the DocumentManager instance.

getClass()

Gets the ClassMetadata instance.

setHydrate(boolean $hydrate)

Sets whether or not to hydrate the documents to objects.

setReadOnly(boolean $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(boolean $refresh)

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

array
getFieldsInQuery() deprecated

Gets the fields involved in this query.

bool
isIndexed() deprecated

Check if this query is indexed.

array
getUnindexedFields() deprecated

Gets an array of the unindexed fields in this query.

mixed
execute()

Execute the query and returns the results.

CursorInterface
prepareCursor(Cursor $cursor)

Prepare the Cursor returned by {@link Query::execute()}.

Details

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

Constructor.

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
boolean $hydrate
boolean $refresh
array $primers
null $requireIndexes deprecated
boolean $readOnly

DocumentManager getDocumentManager()

Gets the DocumentManager instance.

Return Value

DocumentManager $dm

ClassMetadata getClass()

Gets the ClassMetadata instance.

Return Value

ClassMetadata $class

setHydrate(boolean $hydrate)

Sets whether or not to hydrate the documents to objects.

Parameters

boolean $hydrate

setReadOnly(boolean $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

boolean $readOnly

setRefresh(boolean $refresh)

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

This option has no effect if hydration is disabled.

Parameters

boolean $refresh

array getFieldsInQuery() deprecated

deprecated method was deprecated in 1.2 and will be removed in 2.0

Gets the fields involved in this query.

Return Value

array $fields An array of fields names used in this query.

bool isIndexed() deprecated

deprecated method was deprecated in 1.2 and will be removed in 2.0

Check if this query is indexed.

Return Value

bool

array getUnindexedFields() deprecated

deprecated method was deprecated in 1.2 and will be removed in 2.0

Gets an array of the unindexed fields in this query.

Return Value

array

mixed execute()

Execute the query and returns the results.

Return Value

mixed

Exceptions

MongoDBException

protected CursorInterface prepareCursor(Cursor $cursor)

Prepare the Cursor returned by {@link Query::execute()}.

This method will wrap the base Cursor with an ODM Cursor or EagerCursor, and set the hydrate option and UnitOfWork hints. This occurs in addition to any preparation done by the base Query class.

Parameters

Cursor $cursor

Return Value

CursorInterface

See also

\Doctrine\MongoDB\Cursor::prepareCursor()