Package dev.morphia.query
Class FindOptions
- java.lang.Object
-
- dev.morphia.query.FindOptions
-
- All Implemented Interfaces:
dev.morphia.internal.CollectionConfigurable<FindOptions>,dev.morphia.internal.CollectionConfiguration,dev.morphia.internal.ReadConfigurable<FindOptions>
public final class FindOptions extends Object implements dev.morphia.internal.ReadConfigurable<FindOptions>, dev.morphia.internal.CollectionConfigurable<FindOptions>
The options to apply to a find operation (also commonly referred to as a query).- Since:
- 1.3
-
-
Constructor Summary
Constructors Constructor Description FindOptions()Creates an instance with default values
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description FindOptionsallowDiskUse(Boolean allowDiskUse)Enables writing to temporary files on the server.<T> FindIterable<T>apply(FindIterable<T> iterable, Mapper mapper, Class<?> type)FindOptionsbatchSize(int batchSize)Sets the batch sizeFindOptionscollation(Collation collation)Sets the collation to useStringcollection()Returns the alternate collection to use for the operation.FindOptionscollection(String collection)Sets the alternate collection to use for the operation.FindOptionscomment(String comment)Sets the comment to log with the queryFindOptionscomment(BsonValue comment)Sets the comment to log with the queryFindOptionscopy()FindOptionscopy(FindOptions original)Creates an copy of the given optionsCursorTypecursorType()FindOptionscursorType(CursorType cursorType)Sets the cursor typebooleanequals(Object o)BooleangetAllowDiskUse()Deprecated, for removal: This API element is subject to removal in a future version.intgetBatchSize()Deprecated, for removal: This API element is subject to removal in a future version.CollationgetCollation()Deprecated, for removal: This API element is subject to removal in a future version.StringgetComment()Deprecated, for removal: This API element is subject to removal in a future version.CursorTypegetCursorType()Deprecated, for removal: This API element is subject to removal in a future version.DocumentgetHint()Deprecated, for removal: This API element is subject to removal in a future version.intgetLimit()Deprecated, for removal: This API element is subject to removal in a future version.DocumentgetMax()Deprecated, for removal: This API element is subject to removal in a future version.longgetMaxAwaitTime(TimeUnit timeUnit)Deprecated, for removal: This API element is subject to removal in a future version.longgetMaxTime(TimeUnit timeUnit)Deprecated, for removal: This API element is subject to removal in a future version.DocumentgetMin()Deprecated, for removal: This API element is subject to removal in a future version.ProjectiongetProjection()StringgetQueryLogId()Deprecated, for removal: This API element is subject to removal in a future version.intgetSkip()Deprecated, for removal: This API element is subject to removal in a future version.DocumentgetSort()Deprecated, for removal: This API element is subject to removal in a future version.inthashCode()FindOptionshint(DBObject hint)Deprecated, for removal: This API element is subject to removal in a future version.FindOptionshint(String hint)Defines the index hint valueFindOptionshint(Document hint)Sets the index hintFindOptionshintString(String hint)Defines the index hint valuebooleanisLogQuery()This is an internal method.booleanisNoCursorTimeout()Deprecated, for removal: This API element is subject to removal in a future version.booleanisOplogReplay()Deprecated, for removal: This API element is subject to removal in a future version.booleanisPartial()Deprecated, for removal: This API element is subject to removal in a future version.booleanisReturnKey()Deprecated, for removal: This API element is subject to removal in a future version.booleanisShowRecordId()Deprecated, for removal: This API element is subject to removal in a future version.FindOptionslet(Document variables)Add top-level variables to the operation.FindOptionslimit(int limit)Sets the limitFindOptionslogQuery()This is an experimental method.FindOptionsmax(DBObject max)Deprecated, for removal: This API element is subject to removal in a future version.FindOptionsmax(Document max)Sets the max index valueFindOptionsmaxAwaitTime(long maxAwaitTime, TimeUnit timeUnit)Sets the max await timeFindOptionsmaxTime(long maxTime, TimeUnit timeUnit)Sets the max timeFindOptionsmin(DBObject min)Deprecated, for removal: This API element is subject to removal in a future version.FindOptionsmin(Document min)Sets the min index valueFindOptionsnoCursorTimeout(boolean noCursorTimeout)Sets whether to disable cursor time outFindOptionsoplogReplay(boolean oplogReplay)Users should not set this under normal circumstances.FindOptionspartial(boolean partial)Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).Projectionprojection()StringqueryLogId()ReadConcernreadConcern()Gets the read concernFindOptionsreadConcern(ReadConcern readConcern)Sets the read concern to applyReadPreferencereadPreference()FindOptionsreadPreference(ReadPreference readPreference)Sets the read preference to applyFindOptionsreturnKey(boolean returnKey)Sets if only the key value should be returnedFindOptionsshowRecordId(boolean showRecordId)Sets if the record ID should be returnedFindOptionsskip(int skip)Sets how many documents to skipDocumentsort()Deprecated, for removal: This API element is subject to removal in a future version.FindOptionssort(Meta meta)Sets to the sort to useFindOptionssort(Meta meta, Sort... sorts)Sets to the sort to useFindOptionssort(Sort... sorts)Sets to the sort to useFindOptionssort(Document sort)Sets to the sort to useStringtoString()
-
-
-
Method Detail
-
allowDiskUse
public FindOptions allowDiskUse(Boolean allowDiskUse)
Enables writing to temporary files on the server. When set to true, the server can write temporary data to disk while executing the find operation.- Parameters:
allowDiskUse- true to allow disk use- Returns:
- this
- Since:
- 2.2
-
apply
@MorphiaInternal public <T> FindIterable<T> apply(FindIterable<T> iterable, Mapper mapper, Class<?> type)
- Type Parameters:
T- the result type- Parameters:
iterable- the iterable to usemapper- the mapper to usetype- the result type- Returns:
- the iterable instance for the query results
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
batchSize
public FindOptions batchSize(int batchSize)
Sets the batch size- Parameters:
batchSize- the size- Returns:
- this
-
collation
public FindOptions collation(Collation collation)
Sets the collation to use- Parameters:
collation- the collation- Returns:
- this
-
collection
public FindOptions collection(String collection)
Description copied from interface:dev.morphia.internal.CollectionConfigurableSets the alternate collection to use for the operation.- Specified by:
collectionin interfacedev.morphia.internal.CollectionConfigurable<FindOptions>- Parameters:
collection- the name of the collection to use- Returns:
- this
-
collection
public String collection()
Description copied from interface:dev.morphia.internal.CollectionConfigurableReturns the alternate collection to use for the operation. Might return null.- Specified by:
collectionin interfacedev.morphia.internal.CollectionConfigurable<FindOptions>- Returns:
- the collection name or null
-
comment
public FindOptions comment(String comment)
Sets the comment to log with the query- Parameters:
comment- the comment- Returns:
- this
-
comment
public FindOptions comment(BsonValue comment)
Sets the comment to log with the query- Parameters:
comment- the comment- Returns:
- this
-
copy
public FindOptions copy()
- Returns:
- a copy of this instance
-
copy
@MorphiaInternal public FindOptions copy(FindOptions original)
Creates an copy of the given options- Parameters:
original- the original to copy- Returns:
- the new copy
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
cursorType
public FindOptions cursorType(CursorType cursorType)
Sets the cursor type- Parameters:
cursorType- the type- Returns:
- this
-
cursorType
@Nullable @MorphiaInternal public CursorType cursorType()
- Returns:
- the cursor type
- Since:
- 2.3
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getAllowDiskUse
@Deprecated(forRemoval=true, since="2.3") public Boolean getAllowDiskUse()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- true is disk use is allowed
-
getBatchSize
@Deprecated(forRemoval=true, since="2.3") public int getBatchSize()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the batch size
-
getCollation
@Nullable @Deprecated(forRemoval=true, since="2.3") public Collation getCollation()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the collation
-
getComment
@Nullable @Deprecated(forRemoval=true, since="2.3") public String getComment()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the comment
-
getCursorType
@Nullable @Deprecated(forRemoval=true, since="2.3") public CursorType getCursorType()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the cursor type
-
getHint
@Nullable @Deprecated(forRemoval=true, since="2.3") public Document getHint()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the index hint
-
getLimit
@Deprecated(forRemoval=true, since="2.3") public int getLimit()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the limit
-
getMax
@Nullable @Deprecated(forRemoval=true, since="2.3") public Document getMax()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the max value
-
getMaxAwaitTime
@Deprecated(forRemoval=true, since="2.3") public long getMaxAwaitTime(TimeUnit timeUnit)
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
timeUnit- the time unit to apply- Returns:
- the max await time for the operation
-
getMaxTime
@Deprecated(forRemoval=true, since="2.3") public long getMaxTime(TimeUnit timeUnit)
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
timeUnit- the time unit to apply- Returns:
- the max time for the operation
-
getMin
@Nullable @Deprecated(forRemoval=true, since="2.3") public Document getMin()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the min value
-
getProjection
@Nullable @MorphiaInternal public Projection getProjection()
- Returns:
- the projection
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getQueryLogId
@MorphiaInternal @Deprecated(forRemoval=true, since="2.3") public String getQueryLogId()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the query log id used for retrieving the logged query
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getSkip
@Deprecated(forRemoval=true, since="2.3") public int getSkip()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the skip count
-
getSort
@Nullable @Deprecated(forRemoval=true, since="2.3") public Document getSort()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the sort criteria
-
isNoCursorTimeout
@Deprecated(forRemoval=true, since="2.3") public boolean isNoCursorTimeout()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- is the cursor timeout enabled
-
hint
public FindOptions hint(Document hint)
Sets the index hint- Parameters:
hint- the hint- Returns:
- this
-
hint
public FindOptions hint(String hint)
Defines the index hint value- Parameters:
hint- the hint- Returns:
- this
-
hint
@Deprecated(since="2.0", forRemoval=true) public FindOptions hint(DBObject hint)
Deprecated, for removal: This API element is subject to removal in a future version.Defines the index hint value- Parameters:
hint- the hint- Returns:
- this
-
hintString
public FindOptions hintString(String hint)
Defines the index hint value- Parameters:
hint- the hint- Returns:
- this
-
isLogQuery
@MorphiaInternal public boolean isLogQuery()
This is an internal method. It's implementation and presence are subject to change.- Returns:
- this
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
isOplogReplay
@Deprecated(forRemoval=true, since="2.3") public boolean isOplogReplay()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- is oplog replay enabled
-
isPartial
@Deprecated(forRemoval=true, since="2.3") public boolean isPartial()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- are partial results enabled
-
isReturnKey
@Deprecated(forRemoval=true, since="2.3") public boolean isReturnKey()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- is return key only enabled
-
isShowRecordId
@Deprecated(forRemoval=true, since="2.3") public boolean isShowRecordId()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- is showing the record id enabled
-
let
public FindOptions let(Document variables)
Add top-level variables to the operation. A null value means no variables are set.Allows for improved command readability by separating the variables from the query text.
- Parameters:
variables- for find operation or null- Returns:
- this
- Since:
- 2.3
-
queryLogId
@MorphiaInternal public String queryLogId()
- Returns:
- the query log id used for retrieving the logged query
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
limit
public FindOptions limit(int limit)
Sets the limit- Parameters:
limit- the limit- Returns:
- this
-
logQuery
public FindOptions logQuery()
This is an experimental method. It's implementation and presence are subject to change.- Returns:
- this
-
max
public FindOptions max(Document max)
Sets the max index value- Parameters:
max- the max- Returns:
- this
-
max
@Deprecated(since="2.0", forRemoval=true) public FindOptions max(DBObject max)
Deprecated, for removal: This API element is subject to removal in a future version.Defines the max value- Parameters:
max- the max- Returns:
- this
-
maxAwaitTime
public FindOptions maxAwaitTime(long maxAwaitTime, TimeUnit timeUnit)
Sets the max await time- Parameters:
maxAwaitTime- the maxtimeUnit- the unit- Returns:
- this
-
maxTime
public FindOptions maxTime(long maxTime, TimeUnit timeUnit)
Sets the max time- Parameters:
maxTime- the maxtimeUnit- the unit- Returns:
- this
-
min
public FindOptions min(Document min)
Sets the min index value- Parameters:
min- the min- Returns:
- this
-
min
@Deprecated(since="2.0", forRemoval=true) public FindOptions min(DBObject min)
Deprecated, for removal: This API element is subject to removal in a future version.Defines the min value- Parameters:
min- the min- Returns:
- this
-
noCursorTimeout
public FindOptions noCursorTimeout(boolean noCursorTimeout)
Sets whether to disable cursor time out- Parameters:
noCursorTimeout- true if the time should be disabled- Returns:
- this
-
oplogReplay
public FindOptions oplogReplay(boolean oplogReplay)
Users should not set this under normal circumstances.- Parameters:
oplogReplay- if oplog replay is enabled- Returns:
- this
-
partial
public FindOptions partial(boolean partial)
Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).- Parameters:
partial- if partial results for sharded clusters is enabled- Returns:
- this
-
projection
public Projection projection()
- Returns:
- the projection
-
readConcern
public ReadConcern readConcern()
Description copied from interface:dev.morphia.internal.ReadConfigurableGets the read concern- Specified by:
readConcernin interfacedev.morphia.internal.ReadConfigurable<FindOptions>- Returns:
- the read concern
-
readPreference
public ReadPreference readPreference()
- Specified by:
readPreferencein interfacedev.morphia.internal.ReadConfigurable<FindOptions>- Returns:
- the read preference
-
readConcern
public FindOptions readConcern(ReadConcern readConcern)
Description copied from interface:dev.morphia.internal.ReadConfigurableSets the read concern to apply- Specified by:
readConcernin interfacedev.morphia.internal.ReadConfigurable<FindOptions>- Parameters:
readConcern- the read concern- Returns:
- this
-
readPreference
public FindOptions readPreference(ReadPreference readPreference)
Description copied from interface:dev.morphia.internal.ReadConfigurableSets the read preference to apply- Specified by:
readPreferencein interfacedev.morphia.internal.ReadConfigurable<FindOptions>- Parameters:
readPreference- the read preference- Returns:
- this
-
sort
@Nullable @Deprecated(forRemoval=true, since="2.3") @MorphiaInternal public Document sort()
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the sort criteria
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
returnKey
public FindOptions returnKey(boolean returnKey)
Sets if only the key value should be returned- Parameters:
returnKey- true if only the key should be returned- Returns:
- this
-
showRecordId
public FindOptions showRecordId(boolean showRecordId)
Sets if the record ID should be returned- Parameters:
showRecordId- true if the record id should be returned- Returns:
- this
-
skip
public FindOptions skip(int skip)
Sets how many documents to skip- Parameters:
skip- the count- Returns:
- this
-
sort
public FindOptions sort(Meta meta)
Sets to the sort to use- Parameters:
meta- the meta data to sort by- Returns:
- this
- Since:
- 2.0
-
sort
public FindOptions sort(Meta meta, Sort... sorts)
Sets to the sort to use- Parameters:
meta- the meta data to sort bysorts- additional sort elements- Returns:
- this
- Since:
- 2.4
-
sort
public FindOptions sort(Document sort)
Sets to the sort to use- Parameters:
sort- the sort document- Returns:
- this
-
sort
public FindOptions sort(Sort... sorts)
Sets to the sort to use- Parameters:
sorts- the sorts to apply- Returns:
- this
-
-