org.springframework.data.mongodb.core.mapreduce

Class MapReduceOptions

  • java.lang.Object
    • org.springframework.data.mongodb.core.mapreduce.MapReduceOptions


  • public class MapReduceOptions
    extends Object
    Author:
    Mark Pollack, Oliver Gierke, Christoph Strobl, Mark Paluch
    • Constructor Detail

      • MapReduceOptions

        public MapReduceOptions()
    • Method Detail

      • options

        public static MapReduceOptions options()
        Static factory method to create a MapReduceOptions instance
        Returns:
        a new instance
      • limit

        public MapReduceOptions limit(int limit)
        Limit the number of objects to return from the collection that is fed into the map reduce operation Often used in conjunction with a query and sort option so as to reduce the portion of the data that will be processed.
        Parameters:
        limit - Limit the number of objects to process
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • outputCollection

        public MapReduceOptions outputCollection(String collectionName)
        The collection where the results from the map-reduce operation will be stored. Note, you can set the database name as well with the outputDatabase option.
        Parameters:
        collectionName - The name of the collection where the results of the map-reduce operation will be stored.
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • outputDatabase

        public MapReduceOptions outputDatabase(@Nullable
                                               String outputDatabase)
        The database where the results from the map-reduce operation will be stored. Note, you ca set the collection name as well with the outputCollection option.
        Parameters:
        outputDatabase - The name of the database where the results of the map-reduce operation will be stored.
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • outputTypeInline

        public MapReduceOptions outputTypeInline()
        With this option, no collection will be created, and the whole map-reduce operation will happen in RAM. Also, the results of the map-reduce will be returned within the result object. Note that this option is possible only when the result set fits within the 16MB limit of a single document.
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • outputTypeMerge

        public MapReduceOptions outputTypeMerge()
        This option will merge new data into the old output collection. In other words, if the same key exists in both the result set and the old collection, the new key will overwrite the old one.
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • outputTypeReduce

        public MapReduceOptions outputTypeReduce()
        If documents exists for a given key in the result set and in the old collection, then a reduce operation (using the specified reduce function) will be performed on the two values and the result will be written to the output collection. If a finalize function was provided, this will be run after the reduce as well.
        Returns:
      • outputTypeReplace

        public MapReduceOptions outputTypeReplace()
        The output will be inserted into a collection which will atomically replace any existing collection with the same name. Note, the default is MapReduceCommand.OutputType.REPLACE
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • outputSharded

        public MapReduceOptions outputSharded(boolean outputShared)
        If true and combined with an output mode that writes to a collection, the output collection will be sharded using the _id field. For MongoDB 1.9+
        Parameters:
        outputShared - if true, output will be sharded based on _id key.
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • finalizeFunction

        public MapReduceOptions finalizeFunction(@Nullable
                                                 String finalizeFunction)
        Sets the finalize function
        Parameters:
        finalizeFunction - The finalize function. Can be a JSON string or a Spring Resource URL
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • scopeVariables

        public MapReduceOptions scopeVariables(Map<String,Object> scopeVariables)
        Key-value pairs that are placed into JavaScript global scope and can be accessed from map, reduce, and finalize scripts.
        Parameters:
        scopeVariables - variables that can be accessed from map, reduce, and finalize scripts
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • javaScriptMode

        public MapReduceOptions javaScriptMode(boolean javaScriptMode)
        Flag that toggles behavior in the map-reduce operation so as to avoid intermediate conversion to BSON between the map and reduce steps. For MongoDB 1.9+
        Parameters:
        javaScriptMode - if true, have the execution of map-reduce stay in JavaScript
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • verbose

        public MapReduceOptions verbose(boolean verbose)
        Flag to set that will provide statistics on job execution time.
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • extraOption

        @Deprecated
        public MapReduceOptions extraOption(String key,
                                                        Object value)
        Deprecated. since 1.7.
        Add additional extra options that may not have a method on this class. This method will help if you use a version of this client library with a server version that has added additional map-reduce options that do not yet have an method for use in setting them. options
        Parameters:
        key - The key option
        value - The value of the option
        Returns:
        MapReduceOptions so that methods can be chained in a fluent API style
      • collation

        public MapReduceOptions collation(@Nullable
                                          Collation collation)
        Define the Collation specifying language-specific rules for string comparison.
        Parameters:
        collation - can be null.
        Returns:
        Since:
        2.0
      • getOutputType

        public com.mongodb.MapReduceCommand.OutputType getOutputType()
      • getLimit

        @Nullable
        public Integer getLimit()
        Get the maximum number of documents for the input into the map function.
        Returns:
        null if not set.
      • getCollation

        public Optional<Collation> getCollation()
        Get the Collation specifying language-specific rules for string comparison.
        Returns:
        Since:
        2.0
      • getMapReduceAction

        @Nullable
        public com.mongodb.client.model.MapReduceAction getMapReduceAction()
        Return the MapReduceAction derived from MapReduceCommand.OutputType.
        Returns:
        the mapped action or null if the action maps to inline output.
        Since:
        2.0.10
      • usesInlineOutput

        public boolean usesInlineOutput()
        Returns:
        true if MapReduceCommand.OutputType.INLINE is used.
        Since:
        2.0.10
      • getOptionsObject

        public org.bson.Document getOptionsObject()
      • createOutObject

        protected org.bson.Document createOutObject()