db.system.js.save({_id: "extendArray", value: function () { Array.prototype.fancyArrayFunction = function()
{ return 'do something'; }
; }});
db.records.insert(
{foo_id: 1, values:[1,2]}
)
var mapFunction1 = function()
{extendArray(); emit(this.foo_id, this.values); }
;
var reduceFunction1 = function(key, values)
{return values;}
;
db.records.mapReduce(mapFunction1, reduceFunction1,
{ out: "map_reduce_example" }
);
db.map_reduce_example.find({})[0]['value']
[
function _cf9f_anonymous_function() {
return "do something";
},
2
Notice that we have 2 elements in the array as we should, but one of the 2 is the function. If I mongoexport the collection I see all three elements, so the console seems to be having an issue with the length of the array on this also.
./mongoexport --jsonArray -d test3 -c map_reduce_example
connected to: 127.0.0.1
[{ "_id" : 1, "value" : [ 1, 2, function ()
{return "do something";}
] }]
exported 1 records