T
- the operations result type.public class FindOperation<T> extends java.lang.Object implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>>
Modifier and Type | Class and Description |
---|---|
private static class |
FindOperation.ExplainResultCallback |
Modifier and Type | Field and Description |
---|---|
private int |
batchSize |
private Collation |
collation |
private java.lang.String |
comment |
private CursorType |
cursorType |
private Decoder<T> |
decoder |
private BsonDocument |
filter |
private static java.lang.String |
FIRST_BATCH |
private BsonDocument |
hint |
private int |
limit |
private BsonDocument |
max |
private long |
maxAwaitTimeMS |
private long |
maxScan |
private long |
maxTimeMS |
private static java.util.Map<java.lang.String,java.lang.String> |
META_OPERATOR_TO_COMMAND_FIELD_MAP |
private BsonDocument |
min |
private BsonDocument |
modifiers |
private MongoNamespace |
namespace |
private boolean |
noCursorTimeout |
private boolean |
oplogReplay |
private boolean |
partial |
private BsonDocument |
projection |
private ReadConcern |
readConcern |
private boolean |
returnKey |
private boolean |
showRecordId |
private int |
skip |
private boolean |
slaveOk |
private boolean |
snapshot |
private BsonDocument |
sort |
Constructor and Description |
---|
FindOperation(MongoNamespace namespace,
Decoder<T> decoder)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
private BsonDocument |
asDocument(ConnectionDescription connectionDescription,
ReadPreference readPreference) |
ReadOperation<BsonDocument> |
asExplainableOperation(ExplainVerbosity explainVerbosity)
Gets an operation whose execution explains this operation.
|
AsyncReadOperation<BsonDocument> |
asExplainableOperationAsync(ExplainVerbosity explainVerbosity)
Gets an operation whose execution explains this operation.
|
private CommandOperationHelper.CommandTransformer<BsonDocument,AsyncBatchCursor<T>> |
asyncTransformer(AsyncConnectionSource source,
AsyncConnection connection) |
FindOperation<T> |
batchSize(int batchSize)
Sets the number of documents to return per batch.
|
FindOperation<T> |
collation(Collation collation)
Sets the collation options
|
FindOperation<T> |
comment(java.lang.String comment)
Sets the comment to the query.
|
private FindOperation<BsonDocument> |
createExplainableQueryOperation() |
FindOperation<T> |
cursorType(CursorType cursorType)
Sets the cursor type.
|
private QueryResult<T> |
documentToQueryResult(BsonDocument result,
ServerAddress serverAddress) |
private static <T> SingleResultCallback<T> |
exceptionTransformingCallback(SingleResultCallback<T> callback) |
BatchCursor<T> |
execute(ReadBinding binding)
General execute which can return anything of type T
|
void |
executeAsync(AsyncReadBinding binding,
SingleResultCallback<AsyncBatchCursor<T>> callback)
General execute which can return anything of type T
|
FindOperation<T> |
filter(BsonDocument filter)
Sets the query filter to apply to the query.
|
int |
getBatchSize()
Gets the number of documents to return per batch.
|
Collation |
getCollation()
Returns the collation options
|
private BsonDocument |
getCommand() |
java.lang.String |
getComment()
Returns the comment to send with the query.
|
CursorType |
getCursorType()
Get the cursor type.
|
Decoder<T> |
getDecoder()
Gets the decoder used to decode the result documents.
|
BsonDocument |
getFilter()
Gets the query filter.
|
BsonDocument |
getHint()
Returns the hint for which index to use.
|
int |
getLimit()
Gets the limit to apply.
|
BsonDocument |
getMax()
Returns the exclusive upper bound for a specific index.
|
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.
|
long |
getMaxScan()
Returns the maximum number of documents or index keys to scan when executing the query.
|
long |
getMaxTime(java.util.concurrent.TimeUnit timeUnit)
Gets the maximum execution time on the server for this operation.
|
private long |
getMaxTimeForCursor() |
BsonDocument |
getMin()
Returns the minimum inclusive lower bound for a specific index.
|
BsonDocument |
getModifiers()
Gets the query modifiers to apply to this operation.
|
MongoNamespace |
getNamespace()
Gets the namespace.
|
BsonDocument |
getProjection()
Gets a document describing the fields to return for all matching documents.
|
ReadConcern |
getReadConcern()
Gets the read concern
|
int |
getSkip()
Gets the number of documents to skip.
|
BsonDocument |
getSort()
Gets the sort criteria to apply to the query.
|
FindOperation<T> |
hint(BsonDocument hint)
Sets the hint for which index to use.
|
private boolean |
isAwaitData() |
private boolean |
isExplain() |
boolean |
isNoCursorTimeout()
Returns true if cursor timeout has been turned off.
|
boolean |
isOplogReplay()
Internal replication use only.
|
boolean |
isPartial()
Returns true if can get partial results from a mongos if some shards are down.
|
boolean |
isReturnKey()
Returns the returnKey.
|
boolean |
isShowRecordId()
Returns the showRecordId.
|
boolean |
isSlaveOk()
Returns true if set to allowed to query non-primary replica set members.
|
boolean |
isSnapshot()
Returns the snapshot.
|
private boolean |
isTailableCursor() |
FindOperation<T> |
limit(int limit)
Sets the limit to apply.
|
FindOperation<T> |
max(BsonDocument max)
Sets the exclusive upper bound for a specific index.
|
FindOperation<T> |
maxAwaitTime(long maxAwaitTime,
java.util.concurrent.TimeUnit timeUnit)
Sets the maximum await execution time on the server for this operation.
|
FindOperation<T> |
maxScan(long maxScan)
Sets the maximum number of documents or index keys to scan when executing the query.
|
FindOperation<T> |
maxTime(long maxTime,
java.util.concurrent.TimeUnit timeUnit)
Sets the maximum execution time on the server for this operation.
|
FindOperation<T> |
min(BsonDocument min)
Sets the minimum inclusive lower bound for a specific index.
|
FindOperation<T> |
modifiers(BsonDocument modifiers)
Deprecated.
use the individual setters instead
|
FindOperation<T> |
noCursorTimeout(boolean noCursorTimeout)
Sets if the cursor timeout should be turned off.
|
FindOperation<T> |
oplogReplay(boolean oplogReplay)
Internal replication use only.
|
FindOperation<T> |
partial(boolean partial)
Sets if partial results from a mongos if some shards are down are allowed
|
FindOperation<T> |
projection(BsonDocument projection)
Sets a document describing the fields to return for all matching documents.
|
FindOperation<T> |
readConcern(ReadConcern readConcern)
Sets the read concern
|
FindOperation<T> |
returnKey(boolean returnKey)
Sets the returnKey.
|
FindOperation<T> |
showRecordId(boolean showRecordId)
Sets the showRecordId.
|
FindOperation<T> |
skip(int skip)
Sets the number of documents to skip.
|
FindOperation<T> |
slaveOk(boolean slaveOk)
Sets if allowed to query non-primary replica set members.
|
FindOperation<T> |
snapshot(boolean snapshot)
Sets the snapshot.
|
FindOperation<T> |
sort(BsonDocument sort)
Sets the sort criteria to apply to the query.
|
private CommandOperationHelper.CommandTransformer<BsonDocument,BatchCursor<T>> |
transformer(ConnectionSource source,
Connection connection) |
private BsonDocument |
wrapInExplainIfNecessary(BsonDocument commandDocument) |
private static final java.lang.String FIRST_BATCH
private final MongoNamespace namespace
private BsonDocument filter
private int batchSize
private int limit
private BsonDocument modifiers
private BsonDocument projection
private long maxTimeMS
private long maxAwaitTimeMS
private int skip
private BsonDocument sort
private CursorType cursorType
private boolean slaveOk
private boolean oplogReplay
private boolean noCursorTimeout
private boolean partial
private ReadConcern readConcern
private Collation collation
private java.lang.String comment
private BsonDocument hint
private BsonDocument max
private BsonDocument min
private long maxScan
private boolean returnKey
private boolean showRecordId
private boolean snapshot
private static final java.util.Map<java.lang.String,java.lang.String> META_OPERATOR_TO_COMMAND_FIELD_MAP
public FindOperation(MongoNamespace namespace, Decoder<T> decoder)
namespace
- the database and collection namespace for the operation.decoder
- the decoder for the result documents.public MongoNamespace getNamespace()
public Decoder<T> getDecoder()
public BsonDocument getFilter()
public FindOperation<T> filter(BsonDocument filter)
filter
- the filter, which may be null.public int getBatchSize()
public FindOperation<T> batchSize(int batchSize)
batchSize
- the batch sizepublic int getLimit()
public FindOperation<T> limit(int limit)
limit
- the limit, which may be nullpublic BsonDocument getModifiers()
@Deprecated public FindOperation<T> modifiers(BsonDocument modifiers)
modifiers
- the query modifiers to apply, which may be null.public BsonDocument getProjection()
public FindOperation<T> projection(BsonDocument projection)
projection
- the project document, which may be null.public long getMaxTime(java.util.concurrent.TimeUnit timeUnit)
timeUnit
- the time unit to return the result inpublic FindOperation<T> maxTime(long maxTime, java.util.concurrent.TimeUnit timeUnit)
maxTime
- the max timetimeUnit
- the time unit, which may not be nullpublic long getMaxAwaitTime(java.util.concurrent.TimeUnit timeUnit)
timeUnit
- the time unit to return the result inpublic FindOperation<T> maxAwaitTime(long maxAwaitTime, java.util.concurrent.TimeUnit timeUnit)
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 nullpublic int getSkip()
public FindOperation<T> skip(int skip)
skip
- the number of documents to skippublic BsonDocument getSort()
public FindOperation<T> sort(BsonDocument sort)
sort
- the sort criteria, which may be null.public CursorType getCursorType()
public FindOperation<T> cursorType(CursorType cursorType)
cursorType
- the cursor typepublic boolean isSlaveOk()
public FindOperation<T> slaveOk(boolean slaveOk)
slaveOk
- true if allowed to query non-primary replica set members.public boolean isOplogReplay()
public FindOperation<T> oplogReplay(boolean oplogReplay)
oplogReplay
- the oplogReplay valuepublic boolean isNoCursorTimeout()
The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use.
public FindOperation<T> noCursorTimeout(boolean noCursorTimeout)
noCursorTimeout
- true if the cursor timeout should be turned off.public boolean isPartial()
public FindOperation<T> partial(boolean partial)
partial
- allow partial results from a mongos if some shards are downpublic ReadConcern getReadConcern()
public FindOperation<T> readConcern(ReadConcern readConcern)
readConcern
- the read concernpublic Collation getCollation()
public FindOperation<T> collation(Collation collation)
A null value represents the server default.
collation
- the collation options to usepublic java.lang.String getComment()
public FindOperation<T> comment(java.lang.String comment)
comment
- the commentpublic BsonDocument getHint()
public FindOperation<T> hint(BsonDocument hint)
hint
- the hintpublic BsonDocument getMax()
public FindOperation<T> max(BsonDocument max)
max
- the maxpublic BsonDocument getMin()
public FindOperation<T> min(BsonDocument min)
min
- the minpublic long getMaxScan()
public FindOperation<T> maxScan(long maxScan)
maxScan
- the maxScanpublic boolean isReturnKey()
public FindOperation<T> returnKey(boolean returnKey)
returnKey
- the returnKeypublic boolean isShowRecordId()
public FindOperation<T> showRecordId(boolean showRecordId)
$recordId
to the returned documents.showRecordId
- the showRecordIdpublic boolean isSnapshot()
public FindOperation<T> snapshot(boolean snapshot)
snapshot
- the snapshotpublic BatchCursor<T> execute(ReadBinding binding)
ReadOperation
execute
in interface ReadOperation<BatchCursor<T>>
binding
- the binding to execute in the context ofpublic void executeAsync(AsyncReadBinding binding, SingleResultCallback<AsyncBatchCursor<T>> callback)
AsyncReadOperation
executeAsync
in interface AsyncReadOperation<AsyncBatchCursor<T>>
binding
- the binding to execute in the context ofcallback
- the callback to be called when the operation has been executedprivate static <T> SingleResultCallback<T> exceptionTransformingCallback(SingleResultCallback<T> callback)
public ReadOperation<BsonDocument> asExplainableOperation(ExplainVerbosity explainVerbosity)
explainVerbosity
- the explain verbositypublic AsyncReadOperation<BsonDocument> asExplainableOperationAsync(ExplainVerbosity explainVerbosity)
explainVerbosity
- the explain verbosityprivate FindOperation<BsonDocument> createExplainableQueryOperation()
private BsonDocument asDocument(ConnectionDescription connectionDescription, ReadPreference readPreference)
private BsonDocument getCommand()
private BsonDocument wrapInExplainIfNecessary(BsonDocument commandDocument)
private boolean isExplain()
private boolean isTailableCursor()
private boolean isAwaitData()
private CommandOperationHelper.CommandTransformer<BsonDocument,BatchCursor<T>> transformer(ConnectionSource source, Connection connection)
private long getMaxTimeForCursor()
private CommandOperationHelper.CommandTransformer<BsonDocument,AsyncBatchCursor<T>> asyncTransformer(AsyncConnectionSource source, AsyncConnection connection)
private QueryResult<T> documentToQueryResult(BsonDocument result, ServerAddress serverAddress)