Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Use DBObject as type for jsScope in MapReduceCommand #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion casbah-core/src/main/scala/MongoCollection.scala
Expand Up @@ -506,7 +506,7 @@ abstract class MongoCollection extends Logging with Iterable[DBObject] {
sort: Option[DBObject] = None,
limit: Option[Int] = None,
finalizeFunction: Option[JSFunction] = None,
jsScope: Option[String] = None,
jsScope: Option[DBObject] = None,
verbose: Boolean = false): map_reduce.MapReduceResult =
map_reduce.MapReduceResult(getDB.command(MapReduceCommand(name, mapFunction, reduceFunction,
output, query, sort, limit, finalizeFunction,
Expand Down
4 changes: 2 additions & 2 deletions casbah-core/src/main/scala/map_reduce/MapReduceCommand.scala
Expand Up @@ -49,7 +49,7 @@ object MapReduceCommand {
sort: Option[DBObject] = None,
limit: Option[Int] = None,
finalizeFunction: Option[JSFunction] = None,
jsScope: Option[String] = None,
jsScope: Option[DBObject] = None,
verbose: Boolean = false) = {
val mrc = new MapReduceCommand()
mrc.input = input
Expand Down Expand Up @@ -89,7 +89,7 @@ class MapReduceCommand protected[mongodb] () {
var sort: Option[DBObject] = None
var limit: Option[Int] = None
var finalizeFunction: Option[JSFunction] = None
var jsScope: Option[String] = None
var jsScope: Option[DBObject] = None

def toDBObject = {
val dataObj = MongoDBObject.newBuilder
Expand Down
30 changes: 30 additions & 0 deletions casbah-core/src/test/scala/MapReduceSpec.scala
Expand Up @@ -120,6 +120,36 @@ class MapReduceSpec extends CasbahSpecification {
item must beEqualTo(MongoDBObject("_id" -> 90.0, "value" -> 8.552400000000002))
}

"Produce results with variable from jsScope" in {
val f = """
function f( year, value ){
value.scopeVar = scopeVar;
return scopeVar;
}
"""

val coll = mongoDB("yield_historical.in")
val result = coll.mapReduce(
mapJS,
reduceJS,
MapReduceInlineOutput,
finalizeFunction = Some(f),
jsScope = Some(MongoDBObject("scopeVar" -> "testScopeVar")),
verbose = true)

/*log.warn("M/R Result: %s", result)*/


result.isError must beFalse
result.raw.getAs[String]("result") must beNone
result.size must beGreaterThan(0)
result.size must beEqualTo(result.raw.expand[Int]("counts.output").getOrElse(-1))

val item = result.next
item must beDBObject
item must beEqualTo(MongoDBObject("_id" -> 90.0, "value" -> "testScopeVar"))
}

"Produce results for merged output" in {
verifyAndInitTreasuryData

Expand Down