org.mongodb.morphia.query
Interface Query<T>

Type Parameters:
T - The java type to query against
All Superinterfaces:
Cloneable, Iterable<T>, QueryResults<T>
All Known Implementing Classes:
QueryImpl

public interface Query<T>
extends QueryResults<T>, Cloneable

Author:
Scott Hernandez

Method Summary
 CriteriaContainer and(Criteria... criteria)
           
 Query<T> batchSize(int value)
          Batch-size of the fetched result (cursor).
 Query<T> cloneQuery()
          Creates and returns a copy of this Query.
 Query<T> comment(String comment)
          This makes it possible to attach a comment to a query.
 FieldEnd<? extends CriteriaContainerImpl> criteria(String field)
          Criteria builder interface
 Query<T> disableCursorTimeout()
          Disables cursor timeout on server.
 Query<T> disableSnapshotMode()
          Disable snapshotted mode (default mode).
 Query<T> disableValidation()
          Turns off validation (for all calls made after)
 Query<T> enableCursorTimeout()
          Enables cursor timeout on server.
 Query<T> enableSnapshotMode()
          Enabled snapshotted mode where duplicate results (which may be updated during the lifetime of the cursor) will not be returned.
 Query<T> enableValidation()
          Turns on validation (for all calls made after); by default validation is on
 Map<String,Object> explain()
          Provides information on the query plan.
 FieldEnd<? extends Query<T>> field(String field)
          Fluent query interface: createQuery(Ent.class).field("count").greaterThan(7)...
 Query<T> filter(String condition, Object value)
          Create a filter based on the specified condition and value.
 int getBatchSize()
          Returns the batch size
 DBCollection getCollection()
          Returns the DBCollection of the Query.
 Class<T> getEntityClass()
          Returns the entity Class.
 DBObject getFieldsObject()
          Returns the Mongo fields DBObject.
 int getLimit()
          Returns the limit
 int getOffset()
          Returns the offset.
 DBObject getQueryObject()
          Returns the Mongo query DBObject.
 DBObject getSortObject()
          Returns the Mongo sort DBObject.
 Query<T> hintIndex(String idxName)
          Hints as to which index should be used.
 Query<T> limit(int value)
          Limit the fetched result set to a certain number of values.
 Query<T> lowerIndexBound(DBObject lowerBound)
           Specify the inclusive lower bound for a specific index in order to constrain the results of this query.
 Query<T> maxScan(int value)
          Constrains the query to only scan the specified number of documents when fulfilling the query.
 Query<T> maxTime(long maxTime, TimeUnit maxTimeUnit)
          Specifies a time limit for executing the query.
 Query<T> offset(int value)
          Starts the query results at a particular zero-based offset.
 CriteriaContainer or(Criteria... criteria)
           
 Query<T> order(String condition)
          Sorts based on a property (defines return order).
 Query<T> queryNonPrimary()
          Route query to non-primary node
 Query<T> queryPrimaryOnly()
          Route query to primary node
 Query<T> retrievedFields(boolean include, String... fields)
          Limits the fields retrieved
 Query<T> retrieveKnownFields()
          Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes
 Query<T> returnKey()
          Only return the index field or fields for the results of the query.
 Query<T> search(String text)
          Perform a text search on the content of the fields indexed with a text index..
 Query<T> search(String text, String language)
          Perform a text search on the content of the fields indexed with a text index..
 String toString()
          Generates a string that consistently and uniquely specifies this query.
 Query<T> upperIndexBound(DBObject upperBound)
           Specify the exclusive upper bound for a specific index in order to constrain the results of this query.
 Query<T> useReadPreference(ReadPreference readPref)
          Route query ReadPreference
 Query<T> where(CodeWScope js)
          Limit the query using this javascript block; only one per query
 Query<T> where(String js)
          Limit the query using this javascript block; only one per query
 
Methods inherited from interface org.mongodb.morphia.query.QueryResults
asKeyList, asList, countAll, fetch, fetchEmptyEntities, fetchKeys, get, getKey, tail, tail
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

filter

Query<T> filter(String condition,
                Object value)

Create a filter based on the specified condition and value.

Note: Property is in the form of "name op" ("age >").

Valid operators are ["=", "==","!=", "<>", ">", "<", ">=", "<=", "in", "nin", "all", "size", "exists"]

Examples:

You can filter on id properties if this query is restricted to a Class.


field

FieldEnd<? extends Query<T>> field(String field)
Fluent query interface: createQuery(Ent.class).field("count").greaterThan(7)...


criteria

FieldEnd<? extends CriteriaContainerImpl> criteria(String field)
Criteria builder interface


and

CriteriaContainer and(Criteria... criteria)

or

CriteriaContainer or(Criteria... criteria)

where

Query<T> where(String js)
Limit the query using this javascript block; only one per query


where

Query<T> where(CodeWScope js)
Limit the query using this javascript block; only one per query


order

Query<T> order(String condition)

Sorts based on a property (defines return order). Examples:


limit

Query<T> limit(int value)
Limit the fetched result set to a certain number of values.

Parameters:
value - must be >= 0. A value of 0 indicates no limit. For values < 0, use batchSize(int) which is the preferred method

batchSize

Query<T> batchSize(int value)
Batch-size of the fetched result (cursor).

Parameters:
value - must be >= 0. A value of 0 indicates the server default.

maxScan

Query<T> maxScan(int value)
Constrains the query to only scan the specified number of documents when fulfilling the query.

Parameters:
value - must be > 0. A value < 0 indicates no limit
See Also:
http://docs.mongodb.org/manual/reference/operator/meta/maxScan/#op._S_maxScan

maxTime

Query<T> maxTime(long maxTime,
                 TimeUnit maxTimeUnit)
Specifies a time limit for executing the query. Requires server version 2.6 or above.

Parameters:
maxTime - must be > 0. A value < 0 indicates no limit
maxTimeUnit -

comment

Query<T> comment(String comment)
This makes it possible to attach a comment to a query. Because these comments propagate to the profile log, adding comments can make your profile data much easier to interpret and trace.

Parameters:
comment - the comment to add
Returns:
the Query to enable chaining of commands
See Also:
http://docs.mongodb.org/manual/reference/operator/meta/comment/#op._S_comment

returnKey

Query<T> returnKey()
Only return the index field or fields for the results of the query. If $returnKey is set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields

Returns:
the Query to enable chaining of commands
See Also:
Return Key

search

Query<T> search(String text)
Perform a text search on the content of the fields indexed with a text index..

Parameters:
text - the text to search for
Returns:
the Query to enable chaining of commands
See Also:
Text Search

search

Query<T> search(String text,
                String language)
Perform a text search on the content of the fields indexed with a text index..

Parameters:
text - the text to search for
language - the language to use during the search
Returns:
the Query to enable chaining of commands
See Also:
Text Search

offset

Query<T> offset(int value)
Starts the query results at a particular zero-based offset.

Parameters:
value - must be >= 0

upperIndexBound

Query<T> upperIndexBound(DBObject upperBound)

Specify the exclusive upper bound for a specific index in order to constrain the results of this query.

You can chain key/value pairs to build a constraint for a compound index. For instance:

query.upperIndexBound(new BasicDBObject("a", 1).append("b", 2));

to build a constraint on index {"a", "b"}

Parameters:
upperBound - The exclusive upper bound.
See Also:
http://docs.mongodb .org/manual/reference/operator/meta/max/

lowerIndexBound

Query<T> lowerIndexBound(DBObject lowerBound)

Specify the inclusive lower bound for a specific index in order to constrain the results of this query.

You can chain key/value pairs to build a constraint for a compound index. For instance:

query.lowerIndexBound(new BasicDBObject("a", 1).append("b", 2));

to build a constraint on index {"a", "b"}

Parameters:
lowerBound - The inclusive lower bound.
See Also:
http://docs.mongodb .org/manual/reference/operator/meta/min/

enableValidation

Query<T> enableValidation()
Turns on validation (for all calls made after); by default validation is on


disableValidation

Query<T> disableValidation()
Turns off validation (for all calls made after)


hintIndex

Query<T> hintIndex(String idxName)
Hints as to which index should be used.


retrievedFields

Query<T> retrievedFields(boolean include,
                         String... fields)
Limits the fields retrieved


retrieveKnownFields

Query<T> retrieveKnownFields()
Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes


enableSnapshotMode

Query<T> enableSnapshotMode()
Enabled snapshotted mode where duplicate results (which may be updated during the lifetime of the cursor) will not be returned. Not compatible with order/sort and hint. *


disableSnapshotMode

Query<T> disableSnapshotMode()
Disable snapshotted mode (default mode). This will be faster but changes made during the cursor may cause duplicates. *


queryNonPrimary

Query<T> queryNonPrimary()
Route query to non-primary node


queryPrimaryOnly

Query<T> queryPrimaryOnly()
Route query to primary node


useReadPreference

Query<T> useReadPreference(ReadPreference readPref)
Route query ReadPreference


disableCursorTimeout

Query<T> disableCursorTimeout()
Disables cursor timeout on server.


enableCursorTimeout

Query<T> enableCursorTimeout()
Enables cursor timeout on server.


toString

String toString()

Generates a string that consistently and uniquely specifies this query. There is no way to convert this string back into a query and there is no guarantee that the string will be consistent across versions.

In particular, this value is useful as a key for a simple memcache query cache.

Overrides:
toString in class Object

getEntityClass

Class<T> getEntityClass()
Returns the entity Class.


getOffset

int getOffset()
Returns the offset.

See Also:
offset(int)

getLimit

int getLimit()
Returns the limit

See Also:
limit(int)

getBatchSize

int getBatchSize()
Returns the batch size

See Also:
batchSize(int)

getQueryObject

DBObject getQueryObject()
Returns the Mongo query DBObject.


getSortObject

DBObject getSortObject()
Returns the Mongo sort DBObject.


getFieldsObject

DBObject getFieldsObject()
Returns the Mongo fields DBObject.


getCollection

DBCollection getCollection()
Returns the DBCollection of the Query.


explain

Map<String,Object> explain()
Provides information on the query plan. The query plan is the plan the server uses to find the matches for a query. This information may be useful when optimizing a query.

Returns:
Map describing the process used to return the query results.
See Also:
http://docs.mongodb .org/manual/reference/operator/meta/explain/

cloneQuery

Query<T> cloneQuery()
Creates and returns a copy of this Query.