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 collationFindOptionscopy()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 optionscom.mongodb.CursorTypegetCursorType()Get the cursor type.intgetLimit()Gets the limit to apply.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.ReadConcerngetReadConcern()Returns the readConcerncom.mongodb.ReadPreferencegetReadPreference()Returns the readPreferenceintgetSkip()Gets the number of documents to skip.booleanisNoCursorTimeout()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).FindOptionslimit(int limit)Sets the limit to apply.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.FindOptionsmodifier(java.lang.String key, java.lang.Object value)Adds a modifier to the find operationFindOptionsnoCursorTimeout(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 readPreferenceFindOptionsskip(int skip)Sets the number of documents to skip.
-
-
-
Method Detail
-
copy
public FindOptions copy()
Makes a copy of these find options- Returns:
- the new copy
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
modifier
public FindOptions modifier(java.lang.String key, java.lang.Object value)
Adds a modifier to the find operation- Parameters:
key- the modifier namevalue- the modifier value- 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
-
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
-
isOplogReplay
public boolean isOplogReplay()
Users should not set this under normal circumstances.- Returns:
- if oplog replay is enabled
-
oplogReplay
public FindOptions oplogReplay(boolean oplogReplay)
Users should not set this under normal circumstances.- Parameters:
oplogReplay- if oplog replay is enabled- Returns:
- this
-
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
-
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
-
getCursorType
public com.mongodb.CursorType getCursorType()
Get the cursor type.- Returns:
- the cursor type
-
cursorType
public FindOptions cursorType(com.mongodb.CursorType cursorType)
Sets the cursor type.- Parameters:
cursorType- the cursor type- Returns:
- this
-
getReadPreference
public com.mongodb.ReadPreference getReadPreference()
Returns the readPreference- Returns:
- the readPreference
-
readPreference
public FindOptions readPreference(com.mongodb.ReadPreference readPreference)
Sets the readPreference- Parameters:
readPreference- the readPreference- Returns:
- this
-
getReadConcern
public com.mongodb.ReadConcern getReadConcern()
Returns the readConcern- Returns:
- the readConcern
- Since server release
- 3.2
-
readConcern
public FindOptions readConcern(com.mongodb.ReadConcern readConcern)
Sets the readConcern- Parameters:
readConcern- the readConcern- Returns:
- this
- Since server release
- 3.2
-
getCollation
public com.mongodb.client.model.Collation getCollation()
Returns the collation options- Returns:
- the collation options
- Since server release
- 3.4
-
collation
public FindOptions collation(com.mongodb.client.model.Collation collation)
Sets the collation- Parameters:
collation- the collation- Returns:
- this
- Since server release
- 3.4
-
-