相关文章推荐
All Superinterfaces:
java.lang.Iterable<T> , com.mongodb.client.MongoIterable<T> , QueryResults <T>
All Known Implementing Classes:
QueryImpl
public interface Query<T>
extends QueryResults<T>, com.mongodb.client.MongoIterable<T>
CriteriaContainer and​(Criteria... criteria)
Creates a container to hold 'and' clauses
Parameters:
criteria - the clauses to 'and' together
Returns:
the container
batchSize in interface com.mongodb.client.MongoIterable< T >
Parameters:
value - must be >= 0. A value of 0 indicates the server default.
Returns:
See Also:
FindOptions.batchSize(int)
Query < T > comment​(java.lang.String comment)
Deprecated.
use the methods that accept Options directly. This can be replicated with FindOptions.comment(String)
This makes it possible to attach a comment to a query. Because these comments propagate to the profile log, adding comments can make your profile data much easier to interpret and trace.
Parameters:
comment - the comment to add
Returns:
the Query to enable chaining of commands
MongoDB documentation
reference/operator/meta/comment $comment

criteria

FieldEnd<? extends CriteriaContainer> criteria​(java.lang.String field)
Creates a criteria to apply against a field
Parameters:
field - the field
Returns:
the FieldEnd to define the criteria

disableValidation

Query<T> disableValidation()
Turns off validation (for all calls made after)
Returns:

enableValidation

Query<T> enableValidation()
Turns on validation (for all calls made after); by default validation is on
Returns:

explain

java.util.Map<java.lang.String,​java.lang.Object> explain()
Provides information on the query plan. The query plan is the plan the server uses to find the matches for a query. This information may be useful when optimizing a query.
Returns:
Map describing the process used to return the query results.
MongoDB documentation
reference/operator/meta/explain/ explain

explain

java.util.Map<java.lang.String,​java.lang.Object> explain​(FindOptions options)
Provides information on the query plan. The query plan is the plan the server uses to find the matches for a query. This information may be useful when optimizing a query.
Parameters:
options - the options to apply to the explain operation
Returns:
Map describing the process used to return the query results.
Since:
MongoDB documentation
reference/operator/meta/explain/ explain

field

FieldEnd<? extends Query<T>> field​(java.lang.String field)
Fluent query interface: createQuery(Ent.class).field("count").greaterThan(7)...
Parameters:
field - the field
Returns:
the FieldEnd to define the criteria
Query<T> filter​(java.lang.String condition,
                java.lang.Object value)
Create a filter based on the specified condition and value.

Note : Property is in the form of "name op" ("age >").

Valid operators are ["=", "==","!=", "<>", ">", "<", ">=", "<=", "in", "nin", "all", "size", "exists"]

Examples:

  • filter("yearsOfOperation >", 5)
  • filter("rooms.maxBeds >=", 2)
  • filter("rooms.bathrooms exists", 1)
  • filter("stars in", new Long[]{3, 4}) //3 and 4 stars (midrange?)
  • filter("quantity mod", new Long[]{4, 0}) // customers ordered in packs of 4)
  • filter("age >=", age)
  • filter("age =", age)
  • filter("age", age) (if no operator, = is assumed)
  • filter("age !=", age)
  • filter("age in", ageList)
  • filter("customers.loyaltyYears in", yearsList)
  • You can filter on id properties if this query is restricted to a Class .

    Parameters:
    condition - the condition to apply
    value - the value to apply against
    Returns:
    com.mongodb.DBCollection getCollection()
    Deprecated.
    This is an internal method and subject to change or removal. Do not use.
    Returns:
    the collection this query targets
    Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    Query < T > hintIndex​(java.lang.String idxName)
    Deprecated.
    use the methods that accept Options directly. This can be replicated with options.modifier("$hint", idxName)
    Hints as to which index should be used.
    Parameters:
    idxName - the index name to hint
    Returns:
    See Also:
    FindOptions.hint(DBObject)
    use the methods that accept Options directly
    Limit the fetched result set to a certain number of values.
    Parameters:
    value - must be >= 0. A value of 0 indicates no limit. For values < 0, use FindOptions.batchSize(int) which is the preferred method
    Returns:
    See Also:
    FindOptions.limit(int)
    Query < T > lowerIndexBound​(com.mongodb.DBObject lowerBound)
    Deprecated.
    use the methods that accept Options directly.

    Specify the inclusive lower bound for a specific index in order to constrain the results of this query.

    You can chain key/value pairs to build a constraint for a compound index. For instance:

    query.lowerIndexBound(new BasicDBObject("a", 1).append("b", 2));

    to build a constraint on index {"a", "b"}

    Parameters:
    lowerBound - The inclusive lower bound.
    Returns:
    See Also:
    FindOptions.min(DBObject)
    MongoDB documentation
    reference/operator/meta/min/ $min
    no replacement is planned
    Constrains the query to only scan the specified number of documents when fulfilling the query.
    Parameters:
    value - must be > 0. A value < 0 indicates no limit
    Returns:
    MongoDB documentation
    reference/operator/meta/maxScan/#op._S_maxScan $maxScan
    java.util.concurrent.TimeUnit maxTimeUnit)
    Deprecated.
    Specifies a time limit for executing the query. Requires server version 2.6 or above.
    Parameters:
    maxTime - must be > 0. A value < 0 indicates no limit
    maxTimeUnit - the unit of time to use
    Returns:
    See Also:
    FindOptions.maxTime(long, TimeUnit)
    use the methods that accept Options directly
    Starts the query results at a particular zero-based offset.
    Parameters:
    value - must be >= 0
    Returns:
    See Also:
    FindOptions.skip(int)
  • order("-age") (descending order)
  • order("age, date")
  • order("age,-date") (age ascending, date descending)
  • Parameters:
    sort - the sort order to apply
    Returns:
    Query < T > order​( Meta sort)
    Deprecated.
    Sorts based on a metadata (defines return order). Example: order(Meta.textScore()) ({textScore : { $meta: "textScore" }})
    Parameters:
    sort - the sort order to apply
    Returns:
    Query < T > order​( Sort ... sorts)
    Deprecated.
    Sorts based on a specified sort keys (defines return order).
    Parameters:
    sorts - the sort order to apply
    Returns:
    boolean include)
    Deprecated.
    Adds a field to the projection clause. Passing true for include will include the field in the results. Projected fields must all be inclusions or exclusions. You can not include and exclude fields at the same time with the exception of the _id field. The _id field is always included unless explicitly suppressed.
    Parameters:
    field - the field to project
    include - true to include the field in the results
    Returns:
    See Also:
    Project Fields to Return from Query
    ReadPreference.secondary() , ReadPreference.secondaryPreferred() , FindOptions.readPreference(ReadPreference) , ReadPreference.secondary() , ReadPreference.secondaryPreferred()
    ReadPreference.primary() , FindOptions.readPreference(ReadPreference) , ReadPreference.primary() , ReadPreference.primaryPreferred()

    retrieveKnownFields

    Query<T> retrieveKnownFields()
    Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes
    Returns:
    Parameters:
    include - true if the fields should be included in the results. false to exclude them.
    fields - the fields in question
    Returns:
    use the methods that accept Options directly.
    Only return the index field or fields for the results of the query. If $returnKey is set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields
    Returns:
    the Query to enable chaining of commands
    See Also:
    FindOptions.returnKey(boolean)
    MongoDB documentation
    reference/operator/meta/returnKey/#op._S_returnKey $returnKey

    search

    Query<T> search​(java.lang.String text)
    Perform a text search on the content of the fields indexed with a text index..
    Parameters:
    text - the text to search for
    Returns:
    the Query to enable chaining of commands
    MongoDB documentation
    reference/operator/query/text/ $text
    Query<T> search​(java.lang.String text,
                    java.lang.String language)
    Perform a text search on the content of the fields indexed with a text index..
    Parameters:
    text - the text to search for
    language - the language to use during the search
    Returns:
    the Query to enable chaining of commands
    MongoDB documentation
    reference/operator/query/text/ $text
    Query < T > upperIndexBound​(com.mongodb.DBObject upperBound)
    Deprecated.
    use the methods that accept Options directly.

    Specify the exclusive upper bound for a specific index in order to constrain the results of this query.

    You can chain key/value pairs to build a constraint for a compound index. For instance:

    query.upperIndexBound(new BasicDBObject("a", 1).append("b", 2));

    to build a constraint on index {"a", "b"}

    Parameters:
    upperBound - The exclusive upper bound.
    Returns:
    See Also:
    FindOptions.max(DBObject)
    MongoDB documentation
    reference/operator/meta/max/ $max

    useReadPreference

    @Deprecated
    Query<T> useReadPreference​(com.mongodb.ReadPreference readPref)
    Deprecated.
    use the methods that accept Options directly
    Updates the ReadPreference to use
    Parameters:
    readPref - the ReadPreference to use
    Returns:
    See Also:
    ReadPreference , FindOptions.readPreference(ReadPreference)
    Execute the query and get the results (as a List<Key<T>> ) This method is provided as a convenience;
    Returns:
    returns a List of the keys of the documents returned by a query
    Execute the query and get the results (as a List<Key<T>> ) This method is provided as a convenience;
    Parameters:
    options - the options to apply to the find operation
    Returns:
    returns a List of the keys of the documents returned by a query
    Since:
    MorphiaKeyCursor<T> keys()
    Execute the query and get the results (as a MorphiaCursor<Key<T>> )
    Returns:
    the keys of the documents returned by this query
    MorphiaKeyCursor<T> keys​(FindOptions options)
    Execute the query and get the results (as a MorphiaCursor<Key<T>> )
    Parameters:
    options - the options to apply to the find operation
    Returns:
    the keys of the documents returned by this query
    Since:
    options - the options to apply to the find operation
    Returns:
    returns a List of the documents returned by a query
    Since:
    use count() instead
    Count the total number of values in the result, ignoring limit and offset
    Returns:
    the count

    count

    long count()
    Count the total number of values in the result, ignoring limit and offset
    Returns:
    the count
    Since:

    count

    long count​(CountOptions options)
    Count the total number of values in the result, ignoring limit and offset
    Parameters:
    options - the options to apply to the count operation
    Returns:
    the count
    Since:
    MorphiaIterator < T ,​ T > fetch​( FindOptions options)
    Deprecated.
    Execute the query and get the results.
    Parameters:
    options - the options to apply to the find operation
    Returns:
    an Iterator of the results
    Since:
    use keys() instead
    Execute the query and get only the ids of the results. This is more efficient than fetching the actual results (transfers less data).
    Returns:
    an Iterator of the empty entities

    fetchEmptyEntities

    @Deprecated
    MorphiaIterator<T,​T> fetchEmptyEntities​(FindOptions options)
    Deprecated.
    Execute the query and get only the ids of the results. This is more efficient than fetching the actual results (transfers less data).
    Parameters:
    options - the options to apply to the find operation
    Returns:
    an Iterator of the empty entities
    Since:

    first

    T first​(FindOptions options)
    Gets the first entity in the result set. Obeys the Query offset value.
    Parameters:
    options - the options to apply to the find operation
    Returns:
    the only instance in the result, or null if the result set is empty.
    Since:
    use MongoIterable.first()
    Gets the first entity in the result set. Obeys the Query offset value.
    Returns:
    the only instance in the result, or null if the result set is empty.
    Gets the first entity in the result set. Obeys the Query offset value.
    Parameters:
    options - the options to apply to the find operation
    Returns:
    the only instance in the result, or null if the result set is empty.
    Since:
    use MongoIterable.first() instead
    Get the key of the first entity in the result set. Obeys the Query offset value.
    Returns:
    the key of the first instance in the result, or null if the result set is empty.
    use MongoIterable.first() instead
    Get the key of the first entity in the result set. Obeys the Query offset value.
    Parameters:
    options - the options to apply to the find operation
    Returns:
    the key of the first instance in the result, or null if the result set is empty.
    Since:
    MorphiaIterator < T ,​ T > tail()
    Deprecated.
    set the CursorType on FindOptions and use find(FindOptions) instead
    Calls tail(true);
    Returns:
    an Iterator.
    See Also:
    tail(boolean)
    MorphiaIterator < T ,​ T > tail​(boolean awaitData)
    Deprecated.
    set the CursorType on FindOptions and use find(FindOptions) instead. This can be replicated using findOptions.cursorType (awaitData ? TailableAwait : Tailable)
    Returns an tailing iterator over a set of elements of type T. If awaitData is true, this iterator blocks on hasNext() until new data is avail (or some amount of time has passed). Note that if no data is available at all, hasNext() might return immediately. You should wrap tail calls in a loop if you want this to be blocking.
    Parameters:
    awaitData - passes the awaitData to the cursor
    Returns:
    an Iterator.
     
    推荐文章