Package dev.morphia.query
Class MorphiaQuery<T>
- java.lang.Object
-
- dev.morphia.query.MorphiaQuery<T>
-
- Type Parameters:
T
- the type
- All Implemented Interfaces:
Criteria
,CriteriaContainer
,Query<T>
,Iterable<T>
public class MorphiaQuery<T> extends Object implements Query<T>
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MorphiaQuery(Datastore datastore)
protected
MorphiaQuery(Datastore datastore, Class<T> clazz, org.bson.Document query)
protected
MorphiaQuery(Datastore datastore, String collectionName, Class<T> clazz)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
count()
Count the total number of values in the result, ignoring limit and offsetlong
count(CountOptions options)
Count the total number of values in the result, ignoring limit and offsetcom.mongodb.client.result.DeleteResult
delete(DeleteOptions options)
Deletes documents matching this query.Query<T>
disableValidation()
Turns off validation (for all calls made after)Query<T>
enableValidation()
Turns on validation (for all calls made after); by default validation is onboolean
equals(Object o)
Map<String,Object>
explain(FindOptions options)
Provides information on the query plan.FieldEnd<? extends Query<T>>
field(String name)
Fluent query interface:createQuery(Ent.class).field("count").greaterThan(7)...
Query<T>
filter(Filter... additional)
Adds filters to this query.Query<T>
filter(String condition, Object value)
Create a filter based on the specified condition and value.T
findAndDelete(FindAndDeleteOptions options)
Deletes an entity from the database and returns it.T
first()
Gets the first entity in the result set.T
first(FindOptions options)
Gets the first entity in the result set.Class<T>
getEntityClass()
int
hashCode()
dev.morphia.query.internal.MorphiaCursor<T>
iterator()
Execute the query and get the results.dev.morphia.query.internal.MorphiaCursor<T>
iterator(FindOptions options)
Execute the query and get the results.dev.morphia.query.internal.MorphiaKeyCursor<T>
keys()
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)dev.morphia.query.internal.MorphiaKeyCursor<T>
keys(FindOptions options)
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)Modify<T>
modify(UpdateOperator first, UpdateOperator... updates)
Create a modify operation based on this queryQuery<T>
search(String searchText)
Perform a text search on the content of the fields indexed with a text index..Query<T>
search(String searchText, String language)
Perform a text search on the content of the fields indexed with a text index..org.bson.Document
toDocument()
Converts the query to a Document and updates for any discriminator values as my be necessaryString
toString()
Update<T>
update(UpdateOperator first, UpdateOperator... updates)
Creates an update operation based on this query-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface dev.morphia.query.Criteria
attach, getFieldName
-
Methods inherited from interface dev.morphia.query.CriteriaContainer
add, remove
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
count
public long count()
Description copied from interface:Query
Count the total number of values in the result, ignoring limit and offset
-
count
public long count(CountOptions options)
Description copied from interface:Query
Count the total number of values in the result, ignoring limit and offset
-
delete
public com.mongodb.client.result.DeleteResult delete(DeleteOptions options)
Description copied from interface:Query
Deletes documents matching this query. Optionally deleting the first or all matched documents.
-
disableValidation
public Query<T> disableValidation()
Description copied from interface:Query
Turns off validation (for all calls made after)- Specified by:
disableValidation
in interfaceQuery<T>
- Returns:
- this
-
enableValidation
public Query<T> enableValidation()
Description copied from interface:Query
Turns on validation (for all calls made after); by default validation is on- Specified by:
enableValidation
in interfaceQuery<T>
- Returns:
- this
-
explain
public Map<String,Object> explain(FindOptions options)
Description copied from interface:Query
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.
-
field
public FieldEnd<? extends Query<T>> field(String name)
Description copied from interface:Query
Fluent query interface:createQuery(Ent.class).field("count").greaterThan(7)...
-
filter
public Query<T> filter(String condition, Object value)
Description copied from interface:Query
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:
filter("yearsOfOperation >", 5)
filter("rooms.maxBeds >=", 2)
filter("rooms.bathrooms exists", 1)
filter("stars in", new Long[]{3, 4}) //3 and 4 stars (midrange?)
filter("quantity mod", new Long[]{4, 0}) // customers ordered in packs of 4)
filter("age >=", age)
filter("age =", age)
filter("age", age)
(if no operator, = is assumed)filter("age !=", age)
filter("age in", ageList)
filter("customers.loyaltyYears in", yearsList)
You can filter on id properties if this query is restricted to a Class
.
-
filter
public Query<T> filter(Filter... additional)
Description copied from interface:Query
Adds filters to this query. This operation is cumulative.
-
findAndDelete
public T findAndDelete(FindAndDeleteOptions options)
Description copied from interface:Query
Deletes an entity from the database and returns it.- Specified by:
findAndDelete
in interfaceQuery<T>
- Parameters:
options
- the options to apply- Returns:
- the deleted entity
-
first
public T first()
Description copied from interface:Query
Gets the first entity in the result set. Obeys theQuery
offset value.
-
first
public T first(FindOptions options)
Description copied from interface:Query
Gets the first entity in the result set. Obeys theQuery
offset value.
-
getEntityClass
public Class<T> getEntityClass()
- Specified by:
getEntityClass
in interfaceQuery<T>
- Returns:
- the entity
Class
.
-
iterator
public dev.morphia.query.internal.MorphiaCursor<T> iterator()
Description copied from interface:Query
Execute the query and get the results.
-
iterator
public dev.morphia.query.internal.MorphiaCursor<T> iterator(FindOptions options)
Description copied from interface:Query
Execute the query and get the results.
-
keys
public dev.morphia.query.internal.MorphiaKeyCursor<T> keys()
Description copied from interface:Query
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)
-
keys
public dev.morphia.query.internal.MorphiaKeyCursor<T> keys(FindOptions options)
Description copied from interface:Query
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)
-
modify
public Modify<T> modify(UpdateOperator first, UpdateOperator... updates)
Description copied from interface:Query
Create a modify operation based on this query
-
search
public Query<T> search(String searchText)
Description copied from interface:Query
Perform a text search on the content of the fields indexed with a text index..
-
search
public Query<T> search(String searchText, String language)
Description copied from interface:Query
Perform a text search on the content of the fields indexed with a text index..
-
toDocument
public org.bson.Document toDocument()
Converts the query to a Document and updates for any discriminator values as my be necessary- Specified by:
toDocument
in interfaceCriteria
- Specified by:
toDocument
in interfaceQuery<T>
- Returns:
- the query
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
update
public Update<T> update(UpdateOperator first, UpdateOperator... updates)
Description copied from interface:Query
Creates an update operation based on this query
-
-