Package com.mongodb
Class MapReduceCommand
- java.lang.Object
-
- com.mongodb.MapReduceCommand
-
public class MapReduceCommand extends Object
This class groups the argument for a map/reduce operation and can build the underlying command object- MongoDB documentation
- Map-Reduce
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MapReduceCommand.OutputType
Represents the different options available for outputting the results of a map-reduce operation.
-
Constructor Summary
Constructors Constructor Description MapReduceCommand(DBCollection inputCollection, String map, String reduce, String outputCollection, MapReduceCommand.OutputType type, DBObject query)
Represents the command for a map reduce operation Runs the command in REPLACE output type to a named collection
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Boolean
getBypassDocumentValidation()
Gets whether to bypass document validation, or null if unspecified.Collation
getCollation()
Returns the collationString
getFinalize()
Gets the Finalize JS FunctionString
getInput()
Get the name of the collection the MapReduce will read fromBoolean
getJsMode()
Gets the (optional) JavaScript modeint
getLimit()
Gets the (optional) limit on inputString
getMap()
Get the map function, as a JS Stringlong
getMaxTime(TimeUnit timeUnit)
Gets the max execution time for this command, in the given time unit.String
getOutputDB()
Gets the (optional) database name where the output collection should resideString
getOutputTarget()
Gets the output target (name of collection to save to) This value is nullable only if OutputType is set to INLINEMapReduceCommand.OutputType
getOutputType()
Gets the OutputType for this instance.DBObject
getQuery()
Gets the query to run for this MapReduce jobReadPreference
getReadPreference()
Gets the read preferenceString
getReduce()
Gets the reduce function, as a JS StringMap<String,Object>
getScope()
Gets the (optional) JavaScript scopeDBObject
getSort()
Gets the (optional) sort specification objectBoolean
isVerbose()
Gets the verbosity of the MapReduce job.void
setBypassDocumentValidation(Boolean bypassDocumentValidation)
Sets whether to bypass document validation.void
setCollation(Collation collation)
Sets the collation optionsvoid
setFinalize(String finalize)
Sets the Finalize JS Functionvoid
setJsMode(Boolean jsMode)
Sets the (optional) JavaScript Modevoid
setLimit(int limit)
Sets the (optional) limit on inputvoid
setMaxTime(long maxTime, TimeUnit timeUnit)
Sets the max execution time for this command, in the given time unit.void
setOutputDB(String outputDB)
Sets the (optional) database name where the output collection should residevoid
setReadPreference(ReadPreference preference)
Sets the read preference for this command.void
setScope(Map<String,Object> scope)
Sets the (optional) JavaScript scopevoid
setSort(DBObject sort)
Sets the (optional) sort specification objectvoid
setVerbose(Boolean verbose)
Sets the verbosity of the MapReduce job, defaults to 'true'DBObject
toDBObject()
Turns this command into a DBObject representation of this map reduce command.String
toString()
-
-
-
Constructor Detail
-
MapReduceCommand
public MapReduceCommand(DBCollection inputCollection, String map, String reduce, @Nullable String outputCollection, MapReduceCommand.OutputType type, DBObject query)
Represents the command for a map reduce operation Runs the command in REPLACE output type to a named collection- Parameters:
inputCollection
- collection to use as the source documents to perform the map reduce operation.map
- a JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduce
- a JavaScript function that "reduces" to a single object all the values associated with a particular key.outputCollection
- optional - leave null if want to get the result inlinetype
- the type of outputquery
- specifies the selection criteria using query operators for determining the documents input to the map function.- MongoDB documentation
- Map Reduce Command
-
-
Method Detail
-
setVerbose
public void setVerbose(Boolean verbose)
Sets the verbosity of the MapReduce job, defaults to 'true'- Parameters:
verbose
- The verbosity level.
-
isVerbose
public Boolean isVerbose()
Gets the verbosity of the MapReduce job.- Returns:
- the verbosity level.
-
getInput
public String getInput()
Get the name of the collection the MapReduce will read from- Returns:
- name of the collection the MapReduce will read from
-
getMap
public String getMap()
Get the map function, as a JS String- Returns:
- the map function (as a JS String)
-
getReduce
public String getReduce()
Gets the reduce function, as a JS String- Returns:
- the reduce function (as a JS String)
-
getOutputTarget
@Nullable public String getOutputTarget()
Gets the output target (name of collection to save to) This value is nullable only if OutputType is set to INLINE- Returns:
- The outputCollection
-
getOutputType
public MapReduceCommand.OutputType getOutputType()
Gets the OutputType for this instance.- Returns:
- The outputType.
-
getFinalize
@Nullable public String getFinalize()
Gets the Finalize JS Function- Returns:
- The finalize function (as a JS String).
-
setFinalize
public void setFinalize(@Nullable String finalize)
Sets the Finalize JS Function- Parameters:
finalize
- The finalize function (as a JS String)
-
getQuery
@Nullable public DBObject getQuery()
Gets the query to run for this MapReduce job- Returns:
- The query object
-
getSort
@Nullable public DBObject getSort()
Gets the (optional) sort specification object- Returns:
- the Sort DBObject
-
setSort
public void setSort(@Nullable DBObject sort)
Sets the (optional) sort specification object- Parameters:
sort
- The sort specification object
-
getLimit
public int getLimit()
Gets the (optional) limit on input- Returns:
- The limit specification object
-
setLimit
public void setLimit(int limit)
Sets the (optional) limit on input- Parameters:
limit
- The limit specification object
-
getMaxTime
public long getMaxTime(TimeUnit timeUnit)
Gets the max execution time for this command, in the given time unit.- Parameters:
timeUnit
- the time unit to return the value in.- Returns:
- the maximum execution time
- Since:
- 2.12.0
- Since server release
- 2.6
-
setMaxTime
public void setMaxTime(long maxTime, TimeUnit timeUnit)
Sets the max execution time for this command, in the given time unit.- Parameters:
maxTime
- the maximum execution time. A non-zero value requires a server version >= 2.6timeUnit
- the time unit that maxTime is specified in- Since:
- 2.12.0
- Since server release
- 2.6
-
getScope
@Nullable public Map<String,Object> getScope()
Gets the (optional) JavaScript scope- Returns:
- The JavaScript scope
-
setScope
public void setScope(@Nullable Map<String,Object> scope)
Sets the (optional) JavaScript scope- Parameters:
scope
- The JavaScript scope
-
getJsMode
@Nullable public Boolean getJsMode()
Gets the (optional) JavaScript mode- Returns:
- The JavaScript mode
- Since:
- 2.13
-
setJsMode
public void setJsMode(@Nullable Boolean jsMode)
Sets the (optional) JavaScript Mode- Parameters:
jsMode
- Specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions- Since:
- 2.13
-
getOutputDB
@Nullable public String getOutputDB()
Gets the (optional) database name where the output collection should reside- Returns:
- the name of the database the result is stored in, or null.
-
setOutputDB
public void setOutputDB(@Nullable String outputDB)
Sets the (optional) database name where the output collection should reside- Parameters:
outputDB
- the name of the database to send the Map Reduce output to
-
getBypassDocumentValidation
@Nullable public Boolean getBypassDocumentValidation()
Gets whether to bypass document validation, or null if unspecified. The default is null.- Returns:
- whether to bypass document validation, or null if unspecified.
- Since:
- 2.14
- Since server release
- 3.2
-
setBypassDocumentValidation
public void setBypassDocumentValidation(@Nullable Boolean bypassDocumentValidation)
Sets whether to bypass document validation.- Parameters:
bypassDocumentValidation
- whether to bypass document validation, or null if unspecified- Since:
- 2.14
- Since server release
- 3.2
-
toDBObject
public DBObject toDBObject()
Turns this command into a DBObject representation of this map reduce command.- Returns:
- a DBObject that contains the MongoDB document representation of this command.
-
setReadPreference
public void setReadPreference(@Nullable ReadPreference preference)
Sets the read preference for this command. See the * documentation forReadPreference
for more information.- Parameters:
preference
- Read Preference to use
-
getReadPreference
@Nullable public ReadPreference getReadPreference()
Gets the read preference- Returns:
- the readPreference
-
getCollation
@Nullable public Collation getCollation()
Returns the collation- Returns:
- the collation
- Since:
- 3.4
- Since server release
- 3.4
-
setCollation
@Nullable public void setCollation(Collation collation)
Sets the collation options- Parameters:
collation
- the collation options- Since:
- 3.4
- Since server release
- 3.4
-
-