Interface Query<T>

  • Type Parameters:
    T - The java type to query against
    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>
    • Method Detail

      • and

        CriteriaContainer and​(Criteria... criteria)
        Creates a container to hold 'and' clauses
        Parameters:
        criteria - the clauses to 'and' together
        Returns:
        the container
      • batchSize

        @Deprecated
        Query<T> batchSize​(int value)
        Deprecated.
        use the methods that accept Options directly
        Batch-size of the fetched result (cursor).
        Specified by:
        batchSize in interface com.mongodb.client.MongoIterable<T>
        Parameters:
        value - must be >= 0. A value of 0 indicates the server default.
        Returns:
        this
        See Also:
        FindOptions.batchSize(int)
      • cloneQuery

        @Deprecated
        Query<T> cloneQuery()
        Deprecated.
        not supported in 2.0
        Creates and returns a copy of this Query.
        Returns:
        this
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • comment

        @Deprecated
        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
      • disableCursorTimeout

        @Deprecated
        Query<T> disableCursorTimeout()
        Deprecated.
        use the methods that accept Options directly
        Disables cursor timeout on server.
        Returns:
        this
        See Also:
        FindOptions.noCursorTimeout(boolean)
      • disableValidation

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

        @Deprecated
        Query<T> enableCursorTimeout()
        Deprecated.
        use the methods that accept Options directly
        Enables cursor timeout on server.
        Returns:
        this
        See Also:
        FindOptions.noCursorTimeout(boolean)
      • enableValidation

        Query<T> enableValidation()
        Turns on validation (for all calls made after); by default validation is on
        Returns:
        this
      • 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:
        1.3
        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
      • filter

        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:
        this
      • getCollection

        @Deprecated
        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.
      • getEntityClass

        @Deprecated
        java.lang.Class<T> getEntityClass()
        Deprecated.
        Returns:
        the entity Class.
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getFieldsObject

        @Deprecated
        com.mongodb.DBObject getFieldsObject()
        Deprecated.
        Returns:
        the Mongo fields DBObject.
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getOffset

        @Deprecated
        int getOffset()
        Deprecated.
        use the methods that accept Options directly
        Returns:
        the offset.
        See Also:
        offset(int), FindOptions.getSkip()
      • getQueryObject

        @Deprecated
        com.mongodb.DBObject getQueryObject()
        Deprecated.
        Returns:
        the Mongo query DBObject.
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getSortObject

        @Deprecated
        com.mongodb.DBObject getSortObject()
        Deprecated.
        Returns:
        the Mongo sort DBObject.
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • hintIndex

        @Deprecated
        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:
        this
        See Also:
        FindOptions.hint(DBObject)
      • limit

        @Deprecated
        Query<T> limit​(int value)
        Deprecated.
        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:
        this
        See Also:
        FindOptions.limit(int)
      • lowerIndexBound

        @Deprecated
        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:
        this
        See Also:
        FindOptions.min(DBObject)
        MongoDB documentation
        reference/operator/meta/min/ $min
      • maxScan

        @Deprecated
        Query<T> maxScan​(int value)
        Deprecated.
        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:
        this
        MongoDB documentation
        reference/operator/meta/maxScan/#op._S_maxScan $maxScan
      • maxTime

        @Deprecated
        Query<T> maxTime​(long maxTime,
                         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:
        this
        See Also:
        FindOptions.maxTime(long, TimeUnit)
      • offset

        @Deprecated
        Query<T> offset​(int value)
        Deprecated.
        use the methods that accept Options directly
        Starts the query results at a particular zero-based offset.
        Parameters:
        value - must be >= 0
        Returns:
        this
        See Also:
        FindOptions.skip(int)
      • or

        CriteriaContainer or​(Criteria... criteria)
        Creates a container to hold 'or' clauses
        Parameters:
        criteria - the clauses to 'or' together
        Returns:
        the container
      • order

        @Deprecated
        Query<T> order​(java.lang.String sort)
        Deprecated.
        Sorts based on a property (defines return order). Examples:

        • order("age")
        • order("-age") (descending order)
        • order("age, date")
        • order("age,-date") (age ascending, date descending)
        Parameters:
        sort - the sort order to apply
        Returns:
        this
      • order

        @Deprecated
        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:
        this
      • order

        @Deprecated
        Query<T> order​(Sort... sorts)
        Deprecated.
        Sorts based on a specified sort keys (defines return order).
        Parameters:
        sorts - the sort order to apply
        Returns:
        this
      • project

        @Deprecated
        Query<T> project​(java.lang.String field,
                         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:
        this
        See Also:
        Project Fields to Return from Query
      • queryNonPrimary

        @Deprecated
        Query<T> queryNonPrimary()
        Deprecated.
        use the methods that accept Options directly
        Route query to non-primary node
        Returns:
        this
        See Also:
        ReadPreference.secondary(), ReadPreference.secondaryPreferred(), FindOptions.readPreference(ReadPreference), ReadPreference.secondary(), ReadPreference.secondaryPreferred()
      • queryPrimaryOnly

        @Deprecated
        Query<T> queryPrimaryOnly()
        Deprecated.
        use the methods that accept Options directly.
        Route query to primary node
        Returns:
        this
        See Also:
        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:
        this
      • retrievedFields

        @Deprecated
        Query<T> retrievedFields​(boolean include,
                                 java.lang.String... fields)
        Deprecated.
        Limits the fields retrieved
        Parameters:
        include - true if the fields should be included in the results. false to exclude them.
        fields - the fields in question
        Returns:
        this
      • returnKey

        @Deprecated
        Query<T> returnKey()
        Deprecated.
        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
      • search

        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
      • upperIndexBound

        @Deprecated
        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:
        this
        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:
        this
        See Also:
        ReadPreference, FindOptions.readPreference(ReadPreference)
      • where

        @Deprecated
        Query<T> where​(java.lang.String js)
        Deprecated.
        no replacement is planned
        Limit the query using this javascript block; only one per query
        Parameters:
        js - the javascript block to apply
        Returns:
        this
      • where

        @Deprecated
        Query<T> where​(org.bson.types.CodeWScope js)
        Deprecated.
        no replacement is planned
        Limit the query using this javascript block; only one per query
        Parameters:
        js - the javascript block to apply
        Returns:
        this
      • asKeyList

        @Deprecated
        java.util.List<Key<T>> asKeyList()
        Deprecated.
        use keys()
        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
      • asKeyList

        @Deprecated
        java.util.List<Key<T>> asKeyList​(FindOptions options)
        Deprecated.
        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:
        1.3
      • keys

        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
      • keys

        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:
        1.4
      • asList

        @Deprecated
        java.util.List<T> asList()
        Deprecated.
        Execute the query and get the results.
        Returns:
        returns a List of the documents returned by a query
      • asList

        @Deprecated
        java.util.List<T> asList​(FindOptions options)
        Deprecated.
        Execute the query and get the results.
        Parameters:
        options - the options to apply to the find operation
        Returns:
        returns a List of the documents returned by a query
        Since:
        1.3
      • countAll

        @Deprecated
        long countAll()
        Deprecated.
        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:
        1.3
      • 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:
        1.3
      • fetch

        @Deprecated
        MorphiaIterator<T,​T> fetch​(FindOptions options)
        Deprecated.
        use find(FindOptions) instead
        Execute the query and get the results.
        Parameters:
        options - the options to apply to the find operation
        Returns:
        an Iterator of the results
        Since:
        1.3
      • find

        MorphiaCursor<T> find()
        Execute the query and get the results. *note* the return type of this will change in 2.0.
        Returns:
        a MorphiaCursor
        Since:
        1.4
        See Also:
        find(FindOptions)
      • find

        MorphiaCursor<T> find​(FindOptions options)
        Execute the query and get the results.
        Parameters:
        options - the options to apply to the find operation
        Returns:
        a MorphiaCursor
        Since:
        1.4
      • fetchEmptyEntities

        @Deprecated
        MorphiaIterator<T,​T> fetchEmptyEntities()
        Deprecated.
        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.
        use keys(FindOptions) instead
        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:
        1.3
      • fetchKeys

        @Deprecated
        MorphiaKeyIterator<T> fetchKeys​(FindOptions options)
        Deprecated.
        Execute the query and get the keys for the objects.
        Parameters:
        options - the options to apply to the find operation
        Returns:
        the Key Iterator
        Since:
        1.3
      • 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:
        1.5
      • get

        @Deprecated
        T get()
        Deprecated.
        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.
      • get

        @Deprecated
        T get​(FindOptions options)
        Deprecated.
        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:
        1.3
      • getKey

        @Deprecated
        Key<T> getKey()
        Deprecated.
        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.
      • getKey

        @Deprecated
        Key<T> getKey​(FindOptions options)
        Deprecated.
        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:
        1.3
      • tail

        @Deprecated
        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.