Interface Query<T>

    • Method Detail

      • and

        @Deprecated(since="2.0",
                    forRemoval=true)
        default CriteriaContainer and​(Criteria... criteria)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a container to hold 'and' clauses
        Specified by:
        and in interface CriteriaContainer
        Parameters:
        criteria - the clauses to 'and' together
        Returns:
        the container
      • delete

        default com.mongodb.client.result.DeleteResult delete()
        Deletes elements matching this query
        Returns:
        the results
        See Also:
        DeleteOptions
      • filter

        default Query<T> filter​(Filter... filters)
        Adds filters to this query. This operation is cumulative.
        Parameters:
        filters - the filters to add
        Returns:
        this
      • 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
      • execute

        @Deprecated(since="2.0",
                    forRemoval=true)
        default MorphiaCursor<T> execute()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Execute the query and get the results.
        Returns:
        a MorphiaCursor
        See Also:
        iterator()
      • delete

        com.mongodb.client.result.DeleteResult delete​(DeleteOptions options)
        Deletes documents matching this query. Optionally deleting the first or all matched documents.
        Parameters:
        options - the options to apply
        Returns:
        the results
      • disableValidation

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

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

        @Deprecated(since="2.0",
                    forRemoval=true)
        default MorphiaCursor<T> execute​(FindOptions options)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Execute the query and get the results.
        Parameters:
        options - the options to apply to the find operation
        Returns:
        a MorphiaCursor
      • explain

        default Map<String,​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
        explain
      • explain

        default Map<String,​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
        explain
      • explain

        Map<String,​Object> explain​(FindOptions options,
                                         @Nullable
                                         com.mongodb.ExplainVerbosity verbosity)
        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
        verbosity - the verbosity of the explanation
        Returns:
        Map describing the process used to return the query results.
        Since:
        2.2
        MongoDB documentation
        explain
      • field

        @Deprecated(since="2.0",
                    forRemoval=true)
        default FieldEnd<? extends Query<T>> field​(String name)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Fluent query interface: createQuery(Ent.class).field("count").greaterThan(7)...
        Parameters:
        name - the field
        Returns:
        the FieldEnd to define the criteria
      • filter

        @Deprecated(since="2.0",
                    forRemoval=true)
        default Query<T> filter​(String condition,
                                Object value)
        Deprecated, for removal: This API element is subject to removal in a future version.
        use filter(Filter...) instead
        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
      • getLoggedQuery

        String getLoggedQuery()
        Returns:
        The query logged during the previous execution of this query
        Since:
        2.3
      • findAndDelete

        @Nullable
        default T findAndDelete()
        Deletes an entity from the database and returns it.
        Returns:
        the deleted entity
      • findAndDelete

        @Nullable
        T findAndDelete​(FindAndDeleteOptions options)
        Deletes an entity from the database and returns it.
        Parameters:
        options - the options to apply
        Returns:
        the deleted entity
      • first

        @Nullable
        T 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.
        Since:
        1.5
      • first

        @Nullable
        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
      • getEntityClass

        Class<T> getEntityClass()
        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.
      • modify

        @Deprecated(since="2.3",
                    forRemoval=true)
        Modify<T> modify​(UpdateOperator first,
                         UpdateOperator... updates)
        Deprecated, for removal: This API element is subject to removal in a future version.
        consider modify(ModifyOptions, UpdateOperator...) instead. In the next major version, this return type will match the other's return type such that this will be the terminal call for a modify. The only change needed then will be to remove the Modify.execute() call.
        Create a modify operation based on this query
        Parameters:
        first - the first and required update operator
        updates - lists the set of updates to apply
        Returns:
        the modify operation
      • modify

        @Nullable
        default T modify​(ModifyOptions options,
                         UpdateOperator... updates)
        Create a modify operation based on this query
        Parameters:
        updates - lists the set of updates to apply
        options - the options to apply
        Returns:
        the modify operation
        Since:
        2.3
      • iterator

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

        @Deprecated(since="2.0",
                    forRemoval=true)
        MorphiaKeyCursor<T> keys()
        Deprecated, for removal: This API element is subject to removal in a future version.
        use a project to retrieve only the ID values
        Execute the query and get the results (as a MorphiaCursor<Key<T>>)
        Returns:
        the keys of the documents returned by this query
      • keys

        @Deprecated(since="2.0",
                    forRemoval=true)
        MorphiaKeyCursor<T> keys​(FindOptions options)
        Deprecated, for removal: This API element is subject to removal in a future version.
        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
      • or

        @Deprecated(since="2.0",
                    forRemoval=true)
        default CriteriaContainer or​(Criteria... criteria)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a container to hold 'or' clauses
        Specified by:
        or in interface CriteriaContainer
        Parameters:
        criteria - the clauses to 'or' together
        Returns:
        the container
      • modify

        @Deprecated(since="2.0",
                    forRemoval=true)
        default Modify<T> modify​(UpdateOperations<T> operations)
        Deprecated, for removal: This API element is subject to removal in a future version.
        This is only intended for migration of legacy uses of UpdateOperations
        Parameters:
        operations - the prebuilt operations
        Returns:
        the Modify instance
        Since:
        2.0
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • retrieveKnownFields

        @Deprecated(since="2.0",
                    forRemoval=true)
        default Query<T> retrieveKnownFields()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes
        Returns:
        this
      • search

        @Deprecated(since="2.0",
                    forRemoval=true)
        Query<T> search​(String text)
        Deprecated, for removal: This API element is subject to removal in a future version.
        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
        $text
      • search

        @Deprecated(since="2.0",
                    forRemoval=true)
        Query<T> search​(String text,
                        String language)
        Deprecated, for removal: This API element is subject to removal in a future version.
        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
        $text
      • stream

        default Stream<T> stream()
        Provides a Stream representation of the results of this query.
        Returns:
        the stream
        Since:
        2.2
      • stream

        default Stream<T> stream​(FindOptions options)
        Provides a Stream representation of the results of this query.
        Parameters:
        options - the options to apply
        Returns:
        the stream
        Since:
        2.2
      • toDocument

        @MorphiaInternal
        org.bson.Document toDocument()
        Specified by:
        toDocument in interface Criteria
        Returns:
        the document form of this query
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • update

        @Deprecated(since="2.0",
                    forRemoval=true)
        default Update<T> update​(UpdateOperations<T> operations)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Parameters:
        operations - the prebuilt operations
        Returns:
        the Updates instance
        Since:
        2.0
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • update

        default com.mongodb.client.result.UpdateResult update​(Stage... updates)
        Creates an update operation based on this query
        Parameters:
        updates - lists the set of updates to apply
        Returns:
        the update operation
        Since:
        2.3
      • update

        default com.mongodb.client.result.UpdateResult update​(UpdateOptions options,
                                                              Stage... updates)
        Creates an update operation based on this query
        Parameters:
        updates - lists the set of updates to apply
        options - the options to apply
        Returns:
        the update operation
        Since:
        2.3
      • update

        default com.mongodb.client.result.UpdateResult update​(UpdateOptions options,
                                                              UpdateOperator... updates)
        Creates an update operation based on this query
        Parameters:
        updates - lists the set of updates to apply
        options - the options to apply
        Returns:
        the update operation
        Since:
        2.3