public static class Find.Builder extends Object
Find
queries.Modifier and Type | Field and Description |
---|---|
protected boolean |
myAwaitData
If set to true requests for data will block, waiting for data.
|
protected int |
myBatchSize
The number of documents to be returned in each batch of results.
|
protected Document |
myHint
The hint for which index to use.
|
protected String |
myHintName
The hint for which index to use.
|
protected boolean |
myImmortalCursor
If set to true the cursor returned from the query will not timeout or
die automatically, e.g., immortal.
|
protected int |
myLimit
The total number of documents to be returned.
|
protected long |
myMaximumDocumentsToScan
If set then controls the maximum number of documents that will be
scanned for results.
|
protected Document |
myMaximumRange
If set then controls the maximum value for the range within the used
index.
|
protected long |
myMaximumTimeMilliseconds
The maximum amount of time to allow the query to run.
|
protected Document |
myMinimumRange
If set then controls the minimum value for the range within the used
index.
|
protected int |
myNumberToSkip
The number of documents to skip before returning the first document.
|
protected boolean |
myPartialOk
If true then an error in the query should return any partial results.
|
protected Document |
myProjection
The fields to be returned from the matching documents.
|
protected Document |
myQuery
The query document.
|
protected ReadPreference |
myReadPreference
The preference for which servers to use to retrieve the results.
|
protected boolean |
myReturnIndexKeysOnly
If set to true then only the index keys will be returned.
|
protected boolean |
myShowDiskLocation
If set to true then a "$diskLoc" entry will be added to every
returned document with the disk location information.
|
protected boolean |
mySnapshot
If set to true then use snapshot mode to ensure document are only
returned once.
|
protected Document |
mySort
The fields to order the document on.
|
protected boolean |
myTailable
If set to true the cursor returned from the query will be tailable.
|
Constructor and Description |
---|
Find.Builder()
Creates a new Builder.
|
Find.Builder(DocumentAssignable query)
Creates a new Builder.
|
Modifier and Type | Method and Description |
---|---|
Find.Builder |
batchSize(int batchSize)
Sets the value of the number of documents to be returned in each
batch.
|
Find |
build()
Constructs a new
Find object from the state of the builder. |
Find.Builder |
hint(DocumentAssignable indexFields)
Sets the value of hint as to which index should be used to execute
the query.
|
Find.Builder |
hint(Element... indexFields)
Sets the value of hint as to which index should be used to execute
the query.
|
Find.Builder |
hint(String indexName)
Sets the value of hint as to which index should be used to execute
the query.
|
Find.Builder |
immortalCursor()
Sets the cursor returned from the query to never timeout or die
automatically, e.g., immortal.
|
Find.Builder |
immortalCursor(boolean immortal)
If set to true the cursor returned from the query will not timeout or
die automatically, e.g., immortal.
|
Find.Builder |
limit(int limit)
Sets the value of the total number of documents to be returned.
|
Find.Builder |
max(DocumentAssignable maximumRange)
Sets the value of maximum range for the index used to the new value.
|
Find.Builder |
maximumTime(long timeLimit,
TimeUnit timeLimitUnits)
Sets the maximum number of milliseconds to allow the query to run
before aborting the request on the server.
|
Find.Builder |
maxScan(long maximumDocumentsToScan)
Sets the value of maximum number of documents that will be scanned
for results to the new value.
|
Find.Builder |
min(DocumentAssignable minimumRange)
Sets the value of minimum range for the index used to the new value.
|
Find.Builder |
partialOk()
Sets that if there is an error then the query should return any
partial results.
|
Find.Builder |
partialOk(boolean partialOk)
Sets the value of partial okay to the new value.
|
Find.Builder |
projection(DocumentAssignable projection)
Sets the value of the fields to be projected from the matching
documents to the new value.
|
Find.Builder |
projection(String... fieldNames)
Sets the value of the fields to be returned from the matching
documents to the new value.
|
Find.Builder |
query(DocumentAssignable query)
Sets the value of the query document to the new value.
|
Find.Builder |
readPreference(ReadPreference readPreference)
Sets the preference for the set of servers to retrieve the results
from.
|
Find.Builder |
reset()
Resets the builder back to its initial state for reuse.
|
Find.Builder |
returnFields(DocumentAssignable returnFields)
Deprecated.
Replaced with the MongoDB standardized name:
projection . This
method will be removed on or after the 1.4 release. |
Find.Builder |
returnFields(String... fieldNames)
Deprecated.
Replaced with the MongoDB standardized name:
projection . This method
will be removed on or after the 1.4 release. |
Find.Builder |
returnKey()
Sets that only index keys should be returned.
|
Find.Builder |
returnKey(boolean returnIndexKeysOnly)
Sets the value for if only index keys should be returned to the new
value.
|
Find.Builder |
setAwaitData(boolean awaitData)
If set to true requests for data will block, waiting for data.
|
Find.Builder |
setBatchSize(int batchSize)
Sets the value of the number of documents to be returned in each
batch.
|
Find.Builder |
setHint(DocumentAssignable indexFields)
Sets the value of hint as to which index should be used to execute
the query.
|
Find.Builder |
setHint(Element... indexFields)
Sets the value of hint as to which index should be used to execute
the query.
|
Find.Builder |
setHint(String indexName)
Sets the value of hint as to which index should be used to execute
the query.
|
Find.Builder |
setImmortalCursor(boolean immortal)
If set to true the cursor returned from the query will not timeout or
die automatically, e.g., immortal.
|
Find.Builder |
setLimit(int limit)
Sets the value of the total number of documents to be returned.
|
Find.Builder |
setMaximumDocumentsToScan(long maximumDocumentsToScan)
Sets the value of maximum number of documents that will be scanned
for results to the new value.
|
Find.Builder |
setMaximumRange(DocumentAssignable maximumRange)
Sets the value of maximum range for the index used to the new value.
|
Find.Builder |
setMaximumTimeMilliseconds(long maximumTimeMilliseconds)
Sets the maximum number of milliseconds to allow the query to run
before aborting the request on the server.
|
Find.Builder |
setMinimumRange(DocumentAssignable minimumRange)
Sets the value of minimum range for the index used to the new value.
|
Find.Builder |
setNumberToSkip(int numberToSkip)
Sets the value of the number of documents to skip before returning
the first document to the new value.
|
Find.Builder |
setPartialOk(boolean partialOk)
Sets the value of partial okay to the new value.
|
Find.Builder |
setProjection(DocumentAssignable projection)
Sets the value of the fields to be projected or returned from the
matching documents to the new value.
|
Find.Builder |
setQuery(DocumentAssignable query)
Sets the value of the query document to the new value.
|
Find.Builder |
setReadPreference(ReadPreference readPreference)
Sets the preference for the set of servers to retrieve the results
from.
|
Find.Builder |
setReturnFields(DocumentAssignable returnFields)
Deprecated.
Replaced with the MongoDB standardized name:
projection . This method will be
removed on or after the 1.4 release. |
Find.Builder |
setReturnIndexKeysOnly(boolean returnIndexKeysOnly)
Sets the value for if only index keys should be returned to the new
value.
|
Find.Builder |
setShowDiskLocation(boolean showDiskLocation)
Sets the value if the disk location for each document should be
returned to the new value.
|
Find.Builder |
setSnapshot(boolean snapshot)
Sets the value of snapshot to the new value.
|
Find.Builder |
setSort(DocumentAssignable sortFields)
Sets the value of the fields to to sort matching documents by.
|
Find.Builder |
setSort(IntegerElement... sortFields)
Sets the value of the fields to to sort matching documents by.
|
Find.Builder |
setTailable(boolean tailable)
If set to true the cursor returned from the query will be tailable.
|
Find.Builder |
showDiskLoc()
Sets that the disk location for each document should be returned.
|
Find.Builder |
showDiskLoc(boolean showDiskLocation)
Sets the value if the disk location for each document should be
returned to the new value.
|
Find.Builder |
skip(int numberToSkip)
Sets the value of the number of documents to skip before returning
the first document to the new value.
|
Find.Builder |
snapshot()
Sets that the query should ensure that documents are only returned
once.
|
Find.Builder |
snapshot(boolean snapshot)
Sets the value of snapshot to the new value.
|
Find.Builder |
sort(DocumentAssignable sortFields)
Sets the value of the fields to to sort matching documents by.
|
Find.Builder |
sort(IntegerElement... sortFields)
Sets the value of the fields to to sort matching documents by.
|
Find.Builder |
tailable()
Sets the the cursor returned from the query to be
setTailable(true) and
setAwaitData(true) . |
protected boolean myAwaitData
tailable()
cursors.protected int myBatchSize
protected Document myHint
protected String myHintName
protected boolean myImmortalCursor
protected int myLimit
protected long myMaximumDocumentsToScan
protected Document myMaximumRange
protected long myMaximumTimeMilliseconds
protected Document myMinimumRange
protected int myNumberToSkip
protected boolean myPartialOk
protected Document myProjection
protected Document myQuery
protected ReadPreference myReadPreference
protected boolean myReturnIndexKeysOnly
protected boolean myShowDiskLocation
protected boolean mySnapshot
protected Document mySort
protected boolean myTailable
public Find.Builder()
public Find.Builder(DocumentAssignable query)
query
- The query document.public Find.Builder batchSize(int batchSize)
This method delegates to setBatchSize(int)
.
batchSize
- The new value for the number of documents to be returned
in each batch.public Find build()
Find
object from the state of the builder.Find
object.public Find.Builder hint(DocumentAssignable indexFields)
This method delegates to setHint(DocumentAssignable)
.
indexFields
- The new value for the fields of the index to use to
execute the query.public Find.Builder hint(Element... indexFields)
This method delegates to setHint(Element...)
.
This method is intended to be used with the Index
class's
static methods:
import static
com.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; Find.Builder builder = new Find.Builder(); builder.setHint( asc("f"), desc("g") ); ...
indexFields
- The new value for the fields of the index to use to
execute the query.public Find.Builder hint(String indexName)
This method delegates to the setHint(String)
method.
indexName
- The new value for the name of the index to use to execute
the query.public Find.Builder immortalCursor()
This method delegates to setImmortalCursor(true)
. See its JavaDoc for important usage
guidelines.
public Find.Builder immortalCursor(boolean immortal)
This method delegates to setImmortalCursor(boolean)
. See its
JavaDoc important usage guidelines.
immortal
- True if the cursor returned from the query should be
immortal.public Find.Builder limit(int limit)
This method delegates to setLimit(int)
.
limit
- The new value for the total number of documents to be
returned.public Find.Builder max(DocumentAssignable maximumRange)
This method delegates to setMaximumRange(DocumentAssignable)
.
maximumRange
- The new value for the maximum range for the index used.public Find.Builder maximumTime(long timeLimit, TimeUnit timeLimitUnits)
This method equivalent to setMaximumTimeMilliseconds(timeLimitUnits.toMillis(timeLimit)
.
timeLimit
- The new maximum amount of time to allow the query to run.timeLimitUnits
- The units for the maximum amount of time to allow the
query to run.Find.Builder
for method call chaining.public Find.Builder maxScan(long maximumDocumentsToScan)
This method Delegates to setMaximumDocumentsToScan(long)
.
maximumDocumentsToScan
- The new value for the maximum number of documents that
will be scanned for results.public Find.Builder min(DocumentAssignable minimumRange)
This method delegates to setMinimumRange(DocumentAssignable)
.
minimumRange
- The new value for the minimum range for the index used.public Find.Builder partialOk()
This method delegates to setPartialOk(true)
.
public Find.Builder partialOk(boolean partialOk)
This method delegates to setPartialOk(boolean)
.
partialOk
- The new value for the partial okay.public Find.Builder projection(DocumentAssignable projection)
This method delegates to setProjection(DocumentAssignable)
.
projection
- The new value for the fields to be projected from the
matching documents.public Find.Builder projection(String... fieldNames)
This method adds each field to a document with a value of 1
and then delegates to the setProjection(DocumentAssignable)
method.
fieldNames
- The names of the fields to be returned.public Find.Builder query(DocumentAssignable query)
This method delegates to setQuery(DocumentAssignable)
.
query
- The new value for the query document.public Find.Builder readPreference(ReadPreference readPreference)
This method delegates to setReadPreference(ReadPreference)
.
readPreference
- The new value for the preference of which server to return
the results from.public Find.Builder reset()
@Deprecated public Find.Builder returnFields(DocumentAssignable returnFields)
projection
. This
method will be removed on or after the 1.4 release.
This method delegates to projection(DocumentAssignable)
.
returnFields
- The new value for the fields to be returned from the
matching documents.@Deprecated public Find.Builder returnFields(String... fieldNames)
projection
. This method
will be removed on or after the 1.4 release.
This method delegates to the projection(String[])
method.
fieldNames
- The names of the fields to be returned.public Find.Builder returnKey()
This method delegates to setReturnIndexKeysOnly(true)
public Find.Builder returnKey(boolean returnIndexKeysOnly)
This method delegates to setReturnIndexKeysOnly(boolean)
returnIndexKeysOnly
- The new value for if only index keys should be returned.public Find.Builder setAwaitData(boolean awaitData)
tailable()
cursors.awaitData
- True if requests for data will block, waiting for data.
Useful with tailable()
cursors.public Find.Builder setBatchSize(int batchSize)
batchSize
- The new value for the number of documents to be returned
in each batch.public Find.Builder setHint(DocumentAssignable indexFields)
indexFields
- The new value for the fields of the index to use to
execute the query.public Find.Builder setHint(Element... indexFields)
This method is intended to be used with the Index
class's
static methods:
import static
com.allanbank.mongodb.builder.Index.asc
; import staticcom.allanbank.mongodb.builder.Index.desc
; Find.Builder builder = new Find.Builder(); builder.setHint( asc("f"), desc("g") ); ...
indexFields
- The new value for the fields of the index to use to
execute the query.public Find.Builder setHint(String indexName)
indexName
- The new value for the name of the index to use to execute
the query.public Find.Builder setImmortalCursor(boolean immortal)
MongoIterator
or
MongoCursorControl
returned.
Under normal circumstances using an immortal cursor is not needed and its repeated incorrect usage could cause a memory leak on the MongoDB server and impact performance. Extreme caution should be used to ensure the number of active cursors on the server does not grow without bounds.
immortal
- True if the cursor returned from the query should be
immortal.public Find.Builder setLimit(int limit)
limit
- The new value for the total number of documents to be
returned.public Find.Builder setMaximumDocumentsToScan(long maximumDocumentsToScan)
If set to a value greater than zero then controls the maximum number of documents that will be scanned for results.
maximumDocumentsToScan
- The new value for the maximum number of documents that
will be scanned for results.public Find.Builder setMaximumRange(DocumentAssignable maximumRange)
If set then controls the maximum value for the range within the used index.
maximumRange
- The new value for the maximum range for the index used.public Find.Builder setMaximumTimeMilliseconds(long maximumTimeMilliseconds)
maximumTimeMilliseconds
- The new maximum number of milliseconds to allow the query
to run.Find.Builder
for method call chaining.public Find.Builder setMinimumRange(DocumentAssignable minimumRange)
If set then controls the minimum value for the range within the used index.
minimumRange
- The new value for the minimum range for the index used.public Find.Builder setNumberToSkip(int numberToSkip)
numberToSkip
- The new value for the number of documents to skip before
returning the first document.public Find.Builder setPartialOk(boolean partialOk)
partialOk
- The new value for the partial okay.public Find.Builder setProjection(DocumentAssignable projection)
projection
- The new value for the fields to be projected from the
matching documents.public Find.Builder setQuery(DocumentAssignable query)
query
- The new value for the query document.public Find.Builder setReadPreference(ReadPreference readPreference)
readPreference
- The new value for the preference of which server to return
the results from.@Deprecated public Find.Builder setReturnFields(DocumentAssignable returnFields)
projection
. This method will be
removed on or after the 1.4 release.
This method delegates to setProjection(DocumentAssignable)
.
returnFields
- The new value for the fields to be returned from the
matching documents.public Find.Builder setReturnIndexKeysOnly(boolean returnIndexKeysOnly)
If set to true then only the index keys will be returned.
returnIndexKeysOnly
- The new value for if only index keys should be returned.public Find.Builder setShowDiskLocation(boolean showDiskLocation)
If set to true then a "$diskLoc" entry will be added to every returned document with the disk location information.
showDiskLocation
- The new value for the if the disk location for each
document should be returned.public Find.Builder setSnapshot(boolean snapshot)
snapshot
- The new value for the partial okay.public Find.Builder setSort(DocumentAssignable sortFields)
sortFields
- The new value for the fields to sort matching documents
by.public Find.Builder setSort(IntegerElement... sortFields)
This method is intended to be used with the Sort
class's
static methods:
import static
com.allanbank.mongodb.builder.Sort.asc
; import staticcom.allanbank.mongodb.builder.Sort.desc
; Find.Builder builder = new Find.Builder(); builder.setSort( asc("f"), desc("g") ); ...
sortFields
- The new value for the fields to sort matching documents
by.public Find.Builder setTailable(boolean tailable)
Testing has shown that a tailable cursor on an empty collection will
not setup a cursor on the MongoDB server and will immediately return
false from Iterator.hasNext()
.
When using a tailable cursor that has exhausted the available data
will cause the Iterator.hasNext()
calls to block until
more data is available. The connection that is used to request more
documents will also be blocked for short intervals (measured to be
~2.25 seconds with 2.0.7). Any requests submitted behind the cursors
request will also be blocked.
It is highly recommended that the number of connections within the
MongoClientConfiguration
be at least 1 more than the maximum
number of active tailable cursors.
tailable
- The new value for if the cursor returned from the query
will be tailable.public Find.Builder showDiskLoc()
This method delegates to setShowDiskLocation(true)
.
public Find.Builder showDiskLoc(boolean showDiskLocation)
This method delegates to setShowDiskLocation(boolean)
.
showDiskLocation
- The new value for the if the disk location for each
document should be returned.public Find.Builder skip(int numberToSkip)
This method delegates to setNumberToSkip(int)
.
numberToSkip
- The new value for the number of documents to skip before
returning the first document.public Find.Builder snapshot()
This method delegates to setSnapshot(true)
.
public Find.Builder snapshot(boolean snapshot)
This method delegates to setSnapshot(boolean)
.
snapshot
- The new value for the partial okay.public Find.Builder sort(DocumentAssignable sortFields)
This method delegates to setSort(DocumentAssignable)
.
sortFields
- The new value for the fields to sort matching documents
by.public Find.Builder sort(IntegerElement... sortFields)
This method delegates to setSort(IntegerElement...)
.
This method is intended to be used with the Sort
class's
static methods:
import static
com.allanbank.mongodb.builder.Sort.asc
; import staticcom.allanbank.mongodb.builder.Sort.desc
; Find.Builder builder = new Find.Builder(); builder.sort( asc("f"), desc("g") ); ...
sortFields
- The new value for the fields to sort matching documents
by.public Find.Builder tailable()
setTailable(true)
and
setAwaitData(true)
.setTailable(boolean) for important usage
information.
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.