Interface Query<T>

Type Parameters:
T - The java type to query against
All Superinterfaces:
Iterable<T>

public interface Query<T> extends Iterable<T>
  • Method Details

    • delete

      default DeleteResult delete()
      Deletes elements matching this query
      Returns:
      the results
      See Also:
    • filter

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

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

      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

      Map<String,Object> explain(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:
      verbosity - the verbosity of the explanation
      Returns:
      Map describing the process used to return the query results.
      Since:
      2.2
      MongoDB documentation
      explain
    • 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
    • iterator

      MorphiaCursor<T> iterator()
      Execute the query and get the results.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      a MorphiaCursor
      Since:
      2.0
    • modify

      @Nullable default T modify(UpdateOperator first, UpdateOperator... updates)
      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 T modify(ModifyOptions options, UpdateOperator first, UpdateOperator... updates)
      Create a modify operation based on this query
      Parameters:
      updates - lists the set of updates to apply
      first - the first and required update operator
      options - the options to apply
      Returns:
      the modify operation
      Since:
      2.3
    • stream

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

      default UpdateResult update(UpdateOperator... updates)
      Creates an update operation based on this query
      Parameters:
      updates - lists the set of updates to apply
      Returns:
      the update operation
    • update

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

      default UpdateResult update(Stage first, Stage... stages)
      Creates an update operation based on this query
      Parameters:
      first - the first and required stage
      stages - any remaining stages
      Returns:
      the update operation
      Since:
      2.3
    • update

      UpdateResult update(UpdateOptions options, Stage first, Stage... updates)
      Creates an update operation based on this query
      Parameters:
      first - the first and required stage
      updates - lists the set of updates to apply
      options - the options to apply
      Returns:
      the update operation
      Since:
      2.3