Package dev.morphia.query
Interface Query<T>
-
- Type Parameters:
T
- The java type to query against
- All Superinterfaces:
Criteria
,CriteriaContainer
,Iterable<T>
- All Known Implementing Classes:
LegacyQuery
public interface Query<T> extends CriteriaContainer, Iterable<T>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default CriteriaContainer
and(Criteria... criteria)
Deprecated, for removal: This API element is subject to removal in a future version.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 offsetdefault FieldEnd<? extends CriteriaContainer>
criteria(String field)
Deprecated, for removal: This API element is subject to removal in a future version.default DeleteResult
delete()
Deletes elements matching this queryDeleteResult
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 ondefault dev.morphia.query.internal.MorphiaCursor<T>
execute()
Deprecated, for removal: This API element is subject to removal in a future version.default dev.morphia.query.internal.MorphiaCursor<T>
execute(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.default Map<String,Object>
explain()
Provides information on the query plan.default Map<String,Object>
explain(FindOptions options)
Provides information on the query plan.Map<String,Object>
explain(FindOptions options, ExplainVerbosity verbosity)
Provides information on the query plan.default FieldEnd<? extends Query<T>>
field(String name)
Deprecated, for removal: This API element is subject to removal in a future version.default Query<T>
filter(Filter... filters)
Adds filters to this query.default Query<T>
filter(String condition, Object value)
Deprecated, for removal: This API element is subject to removal in a future version.usefilter(Filter...)
insteaddefault dev.morphia.query.internal.MorphiaCursor<T>
find()
Deprecated, for removal: This API element is subject to removal in a future version.useiterator()
default dev.morphia.query.internal.MorphiaCursor<T>
find(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.default T
findAndDelete()
Deletes an entity from the database and returns it.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()
String
getLoggedQuery()
default 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()
Deprecated, for removal: This API element is subject to removal in a future version.use a project to retrieve only the ID valuesdev.morphia.query.internal.MorphiaKeyCursor<T>
keys(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.default T
modify(ModifyOptions options, UpdateOperator... updates)
Create a modify operation based on this querydefault Modify<T>
modify(UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.Modify<T>
modify(UpdateOperator first, UpdateOperator... updates)
Deprecated, for removal: This API element is subject to removal in a future version.considermodify(ModifyOptions, UpdateOperator...)
instead.default CriteriaContainer
or(Criteria... criteria)
Deprecated, for removal: This API element is subject to removal in a future version.default Query<T>
retrieveKnownFields()
Deprecated, for removal: This API element is subject to removal in a future version.Query<T>
search(String text)
Deprecated, for removal: This API element is subject to removal in a future version.useFilters.text(String)
insteadQuery<T>
search(String text, String language)
Deprecated, for removal: This API element is subject to removal in a future version.useFilters.text(String)
insteaddefault Stream<T>
stream()
Provides aStream
representation of the results of this query.default Stream<T>
stream(FindOptions options)
Provides aStream
representation of the results of this query.Document
toDocument()
default UpdateResult
update(Stage... updates)
Creates an update operation based on this querydefault Update<T>
update(UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.Update<T>
update(UpdateOperator first, UpdateOperator... updates)
Deprecated, for removal: This API element is subject to removal in a future version.useupdate(UpdateOptions, UpdateOperator...)
instead.default UpdateResult
update(UpdateOptions options, Stage... updates)
Creates an update operation based on this querydefault UpdateResult
update(UpdateOptions options, UpdateOperator... updates)
Creates an update operation based on this querydefault Update<T>
update(List<UpdateOperator> updates)
Deprecated, for removal: This API element is subject to removal in a future version.useupdate(UpdateOperator, UpdateOperator...)
instead-
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
-
and
@Deprecated(since="2.0", forRemoval=true) default CriteriaContainer and(Criteria... criteria)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a container to hold 'and' clauses- Specified by:
and
in interfaceCriteriaContainer
- Parameters:
criteria
- the clauses to 'and' together- Returns:
- the container
-
criteria
@Deprecated(since="2.0", forRemoval=true) default FieldEnd<? extends CriteriaContainer> criteria(String field)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a criteria to apply against a field- Specified by:
criteria
in interfaceCriteriaContainer
- Parameters:
field
- the field- Returns:
- the FieldEnd to define the criteria
-
delete
default DeleteResult delete()
Deletes elements matching this query- Returns:
- the results
- See Also:
DeleteOptions
-
filter
default Query<T> filter(Filter... filters)
Adds filters to this query. This operation is cumulative.- Parameters:
filters
- the filters to add- Returns:
- this
-
count
long count()
Count the total number of values in the result, ignoring limit and offset- Returns:
- the count
- Since:
- 1.3
-
count
long count(CountOptions options)
Count the total number of values in the result, ignoring limit and offset- Parameters:
options
- the options to apply to the count operation- Returns:
- the count
- Since:
- 1.3
-
execute
@Deprecated(since="2.0", forRemoval=true) default dev.morphia.query.internal.MorphiaCursor<T> execute()
Deprecated, for removal: This API element is subject to removal in a future version.Execute the query and get the results.- Returns:
- a MorphiaCursor
- See Also:
iterator()
-
delete
DeleteResult delete(DeleteOptions options)
Deletes documents matching this query. Optionally deleting the first or all matched documents.- Parameters:
options
- the options to apply- Returns:
- the results
-
disableValidation
Query<T> disableValidation()
Turns off validation (for all calls made after)- Returns:
- this
-
enableValidation
Query<T> enableValidation()
Turns on validation (for all calls made after); by default validation is on- Returns:
- this
-
execute
@Deprecated(since="2.0", forRemoval=true) default dev.morphia.query.internal.MorphiaCursor<T> execute(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.Execute the query and get the results.- Parameters:
options
- the options to apply to the find operation- Returns:
- a MorphiaCursor
-
find
@Deprecated(since="2.0", forRemoval=true) default dev.morphia.query.internal.MorphiaCursor<T> find()
Deprecated, for removal: This API element is subject to removal in a future version.useiterator()
Execute the query and get the results.*note* the return type of this will change in 2.0.
- Returns:
- a MorphiaCursor
- Since:
- 1.4
- See Also:
iterator(FindOptions)
-
explain
default 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.
- MongoDB documentation
- explain
-
explain
default Map<String,Object> explain(FindOptions options)
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.- Parameters:
options
- the options to apply to the explain operation- Returns:
- Map describing the process used to return the query results.
- Since:
- 1.3
- MongoDB documentation
- explain
-
explain
Map<String,Object> explain(FindOptions options, @Nullable ExplainVerbosity verbosity)
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.- Parameters:
options
- the options to apply to the explain operationverbosity
- the verbosity of the explanation- Returns:
- Map describing the process used to return the query results.
- Since:
- 2.2
- MongoDB documentation
- explain
-
field
@Deprecated(since="2.0", forRemoval=true) default FieldEnd<? extends Query<T>> field(String name)
Deprecated, for removal: This API element is subject to removal in a future version.Fluent query interface:createQuery(Ent.class).field("count").greaterThan(7)...
- Parameters:
name
- the field- Returns:
- the FieldEnd to define the criteria
-
filter
@Deprecated(since="2.0", forRemoval=true) default Query<T> filter(String condition, Object value)
Deprecated, for removal: This API element is subject to removal in a future version.usefilter(Filter...)
insteadCreate 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
. - Parameters:
condition
- the condition to applyvalue
- the value to apply against- Returns:
- this
-
getLoggedQuery
String getLoggedQuery()
- Returns:
- The query logged during the previous execution of this query
- Since:
- 2.3
-
findAndDelete
@Nullable default T findAndDelete()
Deletes an entity from the database and returns it.- Returns:
- the deleted entity
-
find
@Deprecated(since="2.0", forRemoval=true) default dev.morphia.query.internal.MorphiaCursor<T> find(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.Execute the query and get the results.- Parameters:
options
- the options to apply to the find operation- Returns:
- a MorphiaCursor
- Since:
- 1.4
-
iterator
default dev.morphia.query.internal.MorphiaCursor<T> iterator()
Execute the query and get the results.- Specified by:
iterator
in interfaceIterable<T>
- Returns:
- a MorphiaCursor
- Since:
- 2.0
- See Also:
iterator(FindOptions)
-
findAndDelete
@Nullable T findAndDelete(FindAndDeleteOptions options)
Deletes an entity from the database and returns it.- Parameters:
options
- the options to apply- Returns:
- the deleted entity
-
first
@Nullable T first()
Gets the first entity in the result set. Obeys theQuery
offset value.- Returns:
- the only instance in the result, or null if the result set is empty.
- Since:
- 1.5
-
first
@Nullable T first(FindOptions options)
Gets the first entity in the result set. Obeys theQuery
offset value.- Parameters:
options
- the options to apply to the find operation- Returns:
- the only instance in the result, or null if the result set is empty.
- Since:
- 1.5
-
getEntityClass
@MorphiaInternal Class<T> getEntityClass()
- Returns:
- the entity
Class
.
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
modify
@Deprecated(since="2.3", forRemoval=true) Modify<T> modify(UpdateOperator first, UpdateOperator... updates)
Deprecated, for removal: This API element is subject to removal in a future version.considermodify(ModifyOptions, UpdateOperator...)
instead. In the next major version, this return type will match the other's return type such that this will be the terminal call for a modify. The only change needed then will be to remove theModify.execute()
call.Create a modify operation based on this query- Parameters:
first
- the first and required update operatorupdates
- lists the set of updates to apply- Returns:
- the modify operation
-
modify
@Nullable default T modify(ModifyOptions options, UpdateOperator... updates)
Create a modify operation based on this query- Parameters:
updates
- lists the set of updates to applyoptions
- the options to apply- Returns:
- the modify operation
- Since:
- 2.3
-
iterator
dev.morphia.query.internal.MorphiaCursor<T> iterator(FindOptions options)
Execute the query and get the results.- Parameters:
options
- the options to apply to the find operation- Returns:
- a MorphiaCursor
- Since:
- 2.0
-
keys
@Deprecated(since="2.0", forRemoval=true) dev.morphia.query.internal.MorphiaKeyCursor<T> keys()
Deprecated, for removal: This API element is subject to removal in a future version.use a project to retrieve only the ID valuesExecute the query and get the results (as aMorphiaCursor<Key<T>>
)- Returns:
- the keys of the documents returned by this query
-
keys
@Deprecated(since="2.0", forRemoval=true) dev.morphia.query.internal.MorphiaKeyCursor<T> keys(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.Execute the query and get the results (as aMorphiaCursor<Key<T>>
)- Parameters:
options
- the options to apply to the find operation- Returns:
- the keys of the documents returned by this query
- Since:
- 1.4
-
or
@Deprecated(since="2.0", forRemoval=true) default CriteriaContainer or(Criteria... criteria)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a container to hold 'or' clauses- Specified by:
or
in interfaceCriteriaContainer
- Parameters:
criteria
- the clauses to 'or' together- Returns:
- the container
-
modify
@MorphiaInternal @Deprecated(since="2.0", forRemoval=true) default Modify<T> modify(UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.This is only intended for migration of legacy uses of UpdateOperations- Parameters:
operations
- the prebuilt operations- Returns:
- the Modify instance
- Since:
- 2.0
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
retrieveKnownFields
@Deprecated(since="2.0", forRemoval=true) default Query<T> retrieveKnownFields()
Deprecated, for removal: This API element is subject to removal in a future version.Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes- Returns:
- this
-
search
@Deprecated(since="2.0", forRemoval=true) Query<T> search(String text)
Deprecated, for removal: This API element is subject to removal in a future version.useFilters.text(String)
insteadPerform 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
- MongoDB documentation
- $text
-
search
@Deprecated(since="2.0", forRemoval=true) Query<T> search(String text, String language)
Deprecated, for removal: This API element is subject to removal in a future version.useFilters.text(String)
insteadPerform a text search on the content of the fields indexed with a text index..- Parameters:
text
- the text to search forlanguage
- the language to use during the search- Returns:
- the Query to enable chaining of commands
- MongoDB documentation
- $text
-
stream
default Stream<T> stream()
Provides aStream
representation of the results of this query.- Returns:
- the stream
- Since:
- 2.2
-
stream
default Stream<T> stream(FindOptions options)
Provides aStream
representation of the results of this query.- Parameters:
options
- the options to apply- Returns:
- the stream
- Since:
- 2.2
-
toDocument
@MorphiaInternal Document toDocument()
- Specified by:
toDocument
in interfaceCriteria
- Returns:
- the document form of this query
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
update
@Deprecated(forRemoval=true) default Update<T> update(List<UpdateOperator> updates)
Deprecated, for removal: This API element is subject to removal in a future version.useupdate(UpdateOperator, UpdateOperator...)
insteadCreates an update operation based on this query- Parameters:
updates
- lists the set of updates to apply- Returns:
- the update operation
-
update
@Deprecated(forRemoval=true) Update<T> update(UpdateOperator first, UpdateOperator... updates)
Deprecated, for removal: This API element is subject to removal in a future version.useupdate(UpdateOptions, UpdateOperator...)
instead. In the next major version, this return type will match the other's return type such that this will be the terminal call for an update. The only change needed then will be to remove theUpdate.execute()
call.Creates an update operation based on this query- Parameters:
first
- the first and required update operatorupdates
- lists the set of updates to apply- Returns:
- the update operation
- See Also:
update(UpdateOptions, UpdateOperator...)
-
update
@MorphiaInternal @Deprecated(since="2.0", forRemoval=true) default Update<T> update(UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
operations
- the prebuilt operations- Returns:
- the Updates instance
- Since:
- 2.0
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
update
default UpdateResult update(Stage... updates)
Creates an update operation based on this query- Parameters:
updates
- lists the set of updates to apply- Returns:
- the update operation
- Since:
- 2.3
-
update
default UpdateResult update(UpdateOptions options, Stage... updates)
Creates an update operation based on this query- Parameters:
updates
- lists the set of updates to applyoptions
- the options to apply- Returns:
- the update operation
- Since:
- 2.3
-
update
default UpdateResult update(UpdateOptions options, UpdateOperator... updates)
Creates an update operation based on this query- Parameters:
updates
- lists the set of updates to applyoptions
- the options to apply- Returns:
- the update operation
- Since:
- 2.3
-
-