public class Query extends Object
Constructor and Description |
---|
Query() |
Query(CriteriaDefinition criteriaDefinition)
Creates a new
Query using the given CriteriaDefinition . |
Modifier and Type | Method and Description |
---|---|
Query |
addCriteria(CriteriaDefinition criteriaDefinition)
Adds the given
CriteriaDefinition to the current Query . |
Query |
allowDiskUse(boolean allowDiskUse)
Enables writing to temporary files for aggregation stages and queries.
|
Query |
allowSecondaryReads()
Allows querying of a replica.
|
Query |
collation(Collation collation)
Set the
Collation applying language-specific rules for string comparison. |
Query |
comment(String comment)
Add a comment to the query that is propagated to the profile log.
|
Query |
cursorBatchSize(int batchSize)
Set the number of documents to return in each response batch.
|
boolean |
equals(Object obj) |
Query |
exhaust() |
Field |
fields() |
Optional<Collation> |
getCollation()
Get the
Collation defining language-specific rules for string comparison. |
protected List<CriteriaDefinition> |
getCriteria() |
org.bson.Document |
getFieldsObject() |
String |
getHint() |
int |
getLimit()
Get the maximum number of documents to be return.
|
Meta |
getMeta() |
org.bson.Document |
getQueryObject() |
Set<Class<?>> |
getRestrictedTypes() |
long |
getSkip()
Get the number of documents to skip.
|
org.bson.Document |
getSortObject() |
int |
hashCode() |
static boolean |
isRestrictedTypeKey(String key)
Deprecated.
don't call this method as the restricted type handling will undergo some significant changes going
forward.
|
boolean |
isSorted()
Returns true if the
Query has a sort parameter. |
Query |
limit(int limit)
Limit the number of returned documents to
limit . |
Query |
maxTime(Duration timeout) |
Query |
maxTime(long timeout,
TimeUnit timeUnit)
Deprecated.
since 2.1. Use
maxTime(Duration) instead. |
Query |
maxTimeMsec(long maxTimeMsec) |
Query |
noCursorTimeout() |
static Query |
of(Query source)
Create an independent copy of the given
Query . |
Query |
partialResults() |
static Query |
query(CriteriaDefinition criteriaDefinition)
Static factory method to create a
Query using the provided CriteriaDefinition . |
protected boolean |
querySettingsEquals(Query that)
Tests whether the settings of the given
Query are equal to this query. |
Query |
restrict(Class<?> type,
Class<?>... additionalTypes)
Restricts the query to only return documents instances that are exactly of the given types.
|
void |
setMeta(Meta meta) |
Query |
skip(long skip)
Set number of documents to skip before returning results.
|
Query |
slaveOk()
Deprecated.
since 3.0.2, use
allowSecondaryReads() . |
String |
toString() |
Query |
with(Pageable pageable)
Sets the given pagination information on the
Query instance. |
Query |
with(Sort sort)
|
Query |
withHint(org.bson.Document hint)
Configures the query to use the given
hint when being executed. |
Query |
withHint(String hint)
Configures the query to use the given hint when being executed.
|
public Query()
public Query(CriteriaDefinition criteriaDefinition)
Query
using the given CriteriaDefinition
.criteriaDefinition
- must not be null.public static Query query(CriteriaDefinition criteriaDefinition)
Query
using the provided CriteriaDefinition
.criteriaDefinition
- must not be null.Query
.public Query addCriteria(CriteriaDefinition criteriaDefinition)
CriteriaDefinition
to the current Query
.criteriaDefinition
- must not be null.public Field fields()
public Query skip(long skip)
skip
- public Query limit(int limit)
limit
.limit
- public Query withHint(String hint)
hint
can either be an index name or a
json Document
representation.hint
- must not be null or empty.Document.parse(String)
public Query withHint(org.bson.Document hint)
hint
when being executed.hint
- must not be null.public Query with(Pageable pageable)
Query
instance. Will transparently set skip
and
limit
as well as applying the Sort
instance defined with the Pageable
.pageable
- must not be null.public Query restrict(Class<?> type, Class<?>... additionalTypes)
type
- may not be nulladditionalTypes
- may not be nullpublic org.bson.Document getQueryObject()
Document
.public org.bson.Document getFieldsObject()
Document
.public org.bson.Document getSortObject()
Document
.public boolean isSorted()
Query
has a sort parameter.Sort.isSorted()
public long getSkip()
public int getLimit()
public Query maxTimeMsec(long maxTimeMsec)
maxTimeMsec
- Meta.setMaxTimeMsec(long)
@Deprecated public Query maxTime(long timeout, TimeUnit timeUnit)
maxTime(Duration)
instead.timeout
- timeUnit
- must not be null.Meta.setMaxTime(long, TimeUnit)
public Query maxTime(Duration timeout)
timeout
- must not be null.Meta.setMaxTime(Duration)
public Query comment(String comment)
comment
- must not be null.Meta.setComment(String)
public Query allowDiskUse(boolean allowDiskUse)
_tmp
subdirectory in the dbPath
directory.
Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a usedDisk
indicator if any aggregation stage wrote data to temporary files due to memory restrictions.
allowDiskUse
- Meta.setAllowDiskUse(Boolean)
public Query cursorBatchSize(int batchSize)
batchSize
- The number of documents to return per batch.Meta.setCursorBatchSize(int)
public Query noCursorTimeout()
Meta.CursorOption.NO_TIMEOUT
public Query exhaust()
Meta.CursorOption.EXHAUST
@Deprecated public Query slaveOk()
allowSecondaryReads()
.Meta.CursorOption.SLAVE_OK
public Query allowSecondaryReads()
Meta.CursorOption.SECONDARY_READS
public Query partialResults()
Meta.CursorOption.PARTIAL
public Meta getMeta()
public void setMeta(Meta meta)
meta
- must not be null.public Query collation(@Nullable Collation collation)
Collation
applying language-specific rules for string comparison.collation
- can be null.public Optional<Collation> getCollation()
Collation
defining language-specific rules for string comparison.protected List<CriteriaDefinition> getCriteria()
public static Query of(Query source)
Query
. Query
will not be binary equal
to the given source but
semantically equal in terms of creating the same result when executed.protected boolean querySettingsEquals(Query that)
Query
are equal to this query.that
- @Deprecated public static boolean isRestrictedTypeKey(String key)
key
- Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.