Class AggregationOptions

java.lang.Object
org.springframework.data.mongodb.core.aggregation.AggregationOptions
All Implemented Interfaces:
ReadConcernAware, ReadPreferenceAware

public class AggregationOptions extends Object implements ReadConcernAware, ReadPreferenceAware
Holds a set of configurable aggregation options that can be used within an aggregation pipeline. A list of support aggregation options can be found in the MongoDB reference documentation.

As off 4.3 allowDiskUse can be null, indicating use of server default, and may only be applied if explicitly set. For compatibility reasons isAllowDiskUse() will remain returning false if the no value has been set.

Since:
1.6
Author:
Thomas Darimont, Oliver Gierke, Christoph Strobl, Mark Paluch, Yadhukrishna S Pai, Soumya Prakash Behera
See Also:
  • Constructor Details

    • AggregationOptions

      public AggregationOptions(boolean allowDiskUse, boolean explain, @Nullable org.bson.Document cursor)
      Creates a new AggregationOptions.
      Parameters:
      allowDiskUse - whether to off-load intensive sort-operations to disk.
      explain - whether to get the execution plan for the aggregation instead of the actual results.
      cursor - can be null, used to pass additional options to the aggregation.
    • AggregationOptions

      public AggregationOptions(boolean allowDiskUse, boolean explain, @Nullable org.bson.Document cursor, @Nullable Collation collation)
      Creates a new AggregationOptions.
      Parameters:
      allowDiskUse - whether to off-load intensive sort-operations to disk.
      explain - whether to get the execution plan for the aggregation instead of the actual results.
      cursor - can be null, used to pass additional options (such as batchSize) to the aggregation.
      collation - collation for string comparison. Can be null.
      Since:
      2.0
    • AggregationOptions

      public AggregationOptions(boolean allowDiskUse, boolean explain, @Nullable org.bson.Document cursor, @Nullable Collation collation, @Nullable String comment)
      Creates a new AggregationOptions.
      Parameters:
      allowDiskUse - whether to off-load intensive sort-operations to disk.
      explain - whether to get the execution plan for the aggregation instead of the actual results.
      cursor - can be null, used to pass additional options (such as batchSize) to the aggregation.
      collation - collation for string comparison. Can be null.
      comment - execution comment. Can be null.
      Since:
      2.2
    • AggregationOptions

      public AggregationOptions(boolean allowDiskUse, boolean explain, int cursorBatchSize)
      Creates a new AggregationOptions.
      Parameters:
      allowDiskUse - whether to off-load intensive sort-operations to disk.
      explain - whether to get the execution plan for the aggregation instead of the actual results.
      cursorBatchSize - initial cursor batch size.
      Since:
      2.0
  • Method Details

    • fromDocument

      public static AggregationOptions fromDocument(org.bson.Document document)
      Creates new AggregationOptions given Document containing aggregation options.
      Parameters:
      document - must not be null.
      Returns:
      the AggregationOptions.
      Since:
      2.0
    • builder

      public static AggregationOptions.Builder builder()
      Obtain a new AggregationOptions.Builder for constructing AggregationOptions.
      Returns:
      never null.
      Since:
      2.0
    • isAllowDiskUse

      public boolean isAllowDiskUse()
      Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp subdirectory in the dbPath directory.
      Returns:
      true if enabled; false otherwise (or if not set).
    • isAllowDiskUseSet

      public boolean isAllowDiskUseSet()
      Return whether isAllowDiskUse() is configured.
      Returns:
      true if is allowDiskUse is configured, false otherwise.
      Since:
      4.2.5
    • isExplain

      public boolean isExplain()
      Specifies to return the information on the processing of the pipeline.
      Returns:
      true if enabled.
    • getCursorBatchSize

      @Nullable public Integer getCursorBatchSize()
      The initial cursor batch size, if available, otherwise null.
      Returns:
      the batch size or null.
      Since:
      2.0
    • getCursor

      public Optional<org.bson.Document> getCursor()
      Specify a document that contains options that control the creation of the cursor object.
      Returns:
      never null.
    • getCollation

      public Optional<Collation> getCollation()
      Get collation settings for string comparison.
      Returns:
      never null.
      Since:
      2.0
    • getComment

      public Optional<String> getComment()
      Get the comment for the aggregation.
      Returns:
      never null.
      Since:
      2.2
    • getHint

      public Optional<org.bson.Document> getHint()
      Deprecated.
      since 4.1, use getHintObject() instead.
      Get the hint used to fulfill the aggregation.
      Returns:
      never null.
      Since:
      3.1
    • getHintObject

      public Optional<Object> getHintObject()
      Get the hint used to fulfill the aggregation.
      Returns:
      never null.
      Since:
      4.1
    • hasReadConcern

      public boolean hasReadConcern()
      Specified by:
      hasReadConcern in interface ReadConcernAware
      Returns:
      true if a ReadConcern is set.
    • getReadConcern

      public com.mongodb.ReadConcern getReadConcern()
      Specified by:
      getReadConcern in interface ReadConcernAware
      Returns:
      the ReadConcern to apply or null if none set.
    • hasReadPreference

      public boolean hasReadPreference()
      Specified by:
      hasReadPreference in interface ReadPreferenceAware
      Returns:
      true if a ReadPreference is set.
    • getReadPreference

      public com.mongodb.ReadPreference getReadPreference()
      Specified by:
      getReadPreference in interface ReadPreferenceAware
      Returns:
      the ReadPreference to apply or null if none set.
    • getMaxTime

      public Duration getMaxTime()
      Returns:
      the time limit for processing. Duration.ZERO is used for the default unbounded behavior.
      Since:
      3.0
    • isSkipResults

      public boolean isSkipResults()
      Returns:
      true to skip results when running an aggregation. Useful in combination with $merge or $out.
      Since:
      3.0.2
    • getDomainTypeMapping

      public AggregationOptions.DomainTypeMapping getDomainTypeMapping()
      Returns:
      the domain type mapping strategy do apply. Never null.
      Since:
      3.2
    • toDocument

      public org.bson.Document toDocument()
      Returns a Document representation of this AggregationOptions.
      Returns:
      never null.
    • hasExecutionTimeLimit

      public boolean hasExecutionTimeLimit()
      Returns:
      true if maxTime is set to a positive value.
      Since:
      3.0
    • toString

      public String toString()
      Overrides:
      toString in class Object