Package dev.morphia.query
Class FindOptions
- java.lang.Object
-
- dev.morphia.query.FindOptions
-
public class FindOptions extends java.lang.ObjectThe 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 empty options instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FindOptionsbatchSize(int batchSize)Sets the number of documents to return per batch.FindOptionscollation(com.mongodb.client.model.Collation collation)Sets the collationFindOptionscomment(java.lang.String comment)FindOptionscopy()Makes a copy of these find optionsFindOptionscursorType(com.mongodb.CursorType cursorType)Sets the cursor type.intgetBatchSize()Gets the number of documents to return per batch.com.mongodb.client.model.CollationgetCollation()Returns the collation optionsjava.lang.StringgetComment()com.mongodb.CursorTypegetCursorType()Get the cursor type.com.mongodb.DBObjectgetHint()intgetLimit()Gets the limit to apply.com.mongodb.DBObjectgetMax()longgetMaxAwaitTime(java.util.concurrent.TimeUnit timeUnit)The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query.longgetMaxTime(java.util.concurrent.TimeUnit timeUnit)Gets the maximum execution time on the server for this operation.com.mongodb.DBObjectgetMin()com.mongodb.ReadConcerngetReadConcern()Returns the readConcerncom.mongodb.ReadPreferencegetReadPreference()Returns the readPreferenceintgetSkip()Gets the number of documents to skip.com.mongodb.DBObjectgetSort()FindOptionshint(com.mongodb.DBObject hint)FindOptionshintString(java.lang.String hint)Defines the index hint valuebooleanisNoCursorTimeout()The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use.booleanisOplogReplay()Users should not set this under normal circumstances.booleanisPartial()Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).booleanisReturnKey()booleanisShowRecordId()FindOptionslimit(int limit)Sets the limit to apply.FindOptionsmax(com.mongodb.DBObject max)FindOptionsmaxAwaitTime(long maxAwaitTime, java.util.concurrent.TimeUnit timeUnit)Sets the maximum await execution time on the server for this operation.FindOptionsmaxTime(long maxTime, java.util.concurrent.TimeUnit timeUnit)Sets the maximum execution time on the server for this operation.FindOptionsmin(com.mongodb.DBObject min)FindOptionsnoCursorTimeout(boolean noCursorTimeout)The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use.FindOptionsoplogReplay(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).FindOptionsreadConcern(com.mongodb.ReadConcern readConcern)Sets the readConcernFindOptionsreadPreference(com.mongodb.ReadPreference readPreference)Sets the readPreferenceFindOptionsreturnKey(boolean returnKey)FindOptionsshowRecordId(boolean showRecordId)FindOptionsskip(int skip)Sets the number of documents to skip.
-
-
-
Method Detail
-
batchSize
public FindOptions batchSize(int batchSize)
Sets the number of documents to return per batch.- Parameters:
batchSize- the batch size- Returns:
- this
- MongoDB documentation
- reference/method/cursor.batchSize/#cursor.batchSize Batch Size
-
collation
public FindOptions collation(com.mongodb.client.model.Collation collation)
Sets the collation- Parameters:
collation- the collation- Returns:
- this
- Since server release
- 3.4
-
comment
public FindOptions comment(java.lang.String comment)
-
copy
public FindOptions copy()
Makes a copy of these find options- Returns:
- the new copy
-
cursorType
public FindOptions cursorType(com.mongodb.CursorType cursorType)
Sets the cursor type.- Parameters:
cursorType- the cursor type- Returns:
- this
-
getBatchSize
public int getBatchSize()
Gets the number of documents to return per batch. Default to 0, which indicates that the server chooses an appropriate batch size.- Returns:
- the batch size, which may be null
- MongoDB documentation
- reference/method/cursor.batchSize/#cursor.batchSize Batch Size
-
getCollation
public com.mongodb.client.model.Collation getCollation()
Returns the collation options- Returns:
- the collation options
- Since server release
- 3.4
-
getComment
@Nullable public java.lang.String getComment()
-
getCursorType
public com.mongodb.CursorType getCursorType()
Get the cursor type.- Returns:
- the cursor type
-
getHint
@Nullable public com.mongodb.DBObject getHint()
-
getLimit
public int getLimit()
Gets the limit to apply. The default is null.- Returns:
- the limit
- MongoDB documentation
- reference/method/cursor.limit/#cursor.limit Limit
-
getMax
@Nullable public com.mongodb.DBObject getMax()
-
getMaxAwaitTime
public long getMaxAwaitTime(java.util.concurrent.TimeUnit timeUnit)
The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. This only applies to a TAILABLE_AWAIT cursor. When the cursor is not a TAILABLE_AWAIT cursor, this option is ignored.On servers >= 3.2, this option will be specified on the getMore command as "maxTimeMS". The default is no value: no "maxTimeMS" is sent to the server with the getMore command.
On servers < 3.2, this option is ignored, and indicates that the driver should respect the server's default value
A zero value will be ignored.
- Parameters:
timeUnit- the time unit to return the result in- Returns:
- the maximum await execution time in the given time unit
- MongoDB documentation
- reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
-
getMaxTime
public long getMaxTime(java.util.concurrent.TimeUnit timeUnit)
Gets the maximum execution time on the server for this operation. The default is 0, which places no limit on the execution time.- Parameters:
timeUnit- the time unit to return the result in- Returns:
- the maximum execution time in the given time unit
- MongoDB documentation
- reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
-
getMin
@Nullable public com.mongodb.DBObject getMin()
-
getReadConcern
public com.mongodb.ReadConcern getReadConcern()
Returns the readConcern- Returns:
- the readConcern
- Since server release
- 3.2
-
getReadPreference
public com.mongodb.ReadPreference getReadPreference()
Returns the readPreference- Returns:
- the readPreference
-
getSkip
public int getSkip()
Gets the number of documents to skip. The default is 0.- Returns:
- the number of documents to skip, which may be null
- MongoDB documentation
- reference/method/cursor.skip/#cursor.skip Skip
-
getSort
@Nullable public com.mongodb.DBObject getSort()
-
hint
public FindOptions hint(com.mongodb.DBObject hint)
-
hintString
public FindOptions hintString(java.lang.String hint)
Defines the index hint value- Parameters:
hint- the hint- Returns:
- this
-
isNoCursorTimeout
public boolean isNoCursorTimeout()
The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. If true, that timeout is disabled.- Returns:
- true if cursor timeout is disabled
-
isOplogReplay
public boolean isOplogReplay()
Users should not set this under normal circumstances.- Returns:
- if oplog replay is enabled
-
isPartial
public boolean isPartial()
Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).- Returns:
- if partial results for sharded clusters is enabled
-
isReturnKey
public boolean isReturnKey()
-
isShowRecordId
public boolean isShowRecordId()
-
limit
public FindOptions limit(int limit)
Sets the limit to apply.- Parameters:
limit- the limit, which may be null- Returns:
- this
- MongoDB documentation
- reference/method/cursor.limit/#cursor.limit Limit
-
max
public FindOptions max(com.mongodb.DBObject max)
-
maxAwaitTime
public FindOptions maxAwaitTime(long maxAwaitTime, java.util.concurrent.TimeUnit timeUnit)
Sets the maximum await execution time on the server for this operation.- Parameters:
maxAwaitTime- the max await time. A zero value will be ignored, and indicates that the driver should respect the server's default valuetimeUnit- the time unit, which may not be null- Returns:
- this
- MongoDB documentation
- reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
-
maxTime
public FindOptions maxTime(long maxTime, java.util.concurrent.TimeUnit timeUnit)
Sets the maximum execution time on the server for this operation.- Parameters:
maxTime- the max timetimeUnit- the time unit, which may not be null- Returns:
- this
- MongoDB documentation
- reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time
-
min
public FindOptions min(com.mongodb.DBObject min)
-
noCursorTimeout
public FindOptions noCursorTimeout(boolean noCursorTimeout)
The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.- Parameters:
noCursorTimeout- true if cursor timeout is 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
-
readConcern
public FindOptions readConcern(com.mongodb.ReadConcern readConcern)
Sets the readConcern- Parameters:
readConcern- the readConcern- Returns:
- this
- Since server release
- 3.2
-
readPreference
public FindOptions readPreference(com.mongodb.ReadPreference readPreference)
Sets the readPreference- Parameters:
readPreference- the readPreference- Returns:
- this
-
returnKey
public FindOptions returnKey(boolean returnKey)
-
showRecordId
public FindOptions showRecordId(boolean showRecordId)
-
skip
public FindOptions skip(int skip)
Sets the number of documents to skip.- Parameters:
skip- the number of documents to skip- Returns:
- this
- MongoDB documentation
- reference/method/cursor.skip/#cursor.skip Skip
-
-