| Steps To Reproduce: |
Create some test data:
use test
|
db.test.drop()
|
db.test.insert({ _id : 1, x : 1 })
|
db.test.insert({ _id : 2, x : 2 })
|
db.test.insert({ _id : 3, x : 2 })
|
Define map and reduce functions and call mapReduce:
var map = "function map() { emit(this.x, 1); }"
|
var reduce = "function reduce(key, values) { return values.length; }"
|
|
db.test.mapReduce(map, reduce, { out : { inline : 1 } })
|
The result is:
{
|
"results" : [
|
{
|
"_id" : 1,
|
"value" : 1
|
},
|
{
|
"_id" : 2,
|
"value" : 2
|
}
|
],
|
"timeMillis" : 12,
|
"counts" : {
|
"input" : 3,
|
"emit" : 3,
|
"reduce" : 1,
|
"output" : 2
|
},
|
"ok" : 1
|
}
|
Now add a semicolon to the end of the string for the map function:
var map = "function map() { emit(this.x, 1); };"
|
|
db.test.mapReduce(map, reduce, { out : { inline : 1 } })
|
This time the result is:
{
|
"results" : [ ],
|
"timeMillis" : 14,
|
"counts" : {
|
"input" : 3,
|
"emit" : 0,
|
"reduce" : 0,
|
"output" : 0
|
},
|
"ok" : 1
|
}
|
Note the empty results array and the 0 emit count.
|