mongoDb的mapReduce问题 这是我插入的数据格式
> for (var i = 0; i < 1000; i++) {
... var u = { name : "user" + i, age : i % 40 + 1, sex : i % 2 };
... db.users.insert(u);
... }
下面是Map函数
> m = function() { emit(this.age, 1) }
下面是Reduce
> r = function(key, values) {
... var x = 0;
... values.forEach(function(v) { x += v });
... return x;
... }
Result
> res = db.users.mapReduce(m, r) 执行这行后就报错
错误如下:
("assert failed : need to an optionsOrOutString")@shell/utils.js:32
(undefined,"need to an optionsOrOutString")@shell/utils.js:42
((function () {emit(this.age, 1);}),(function (key, values) {var x = 0;values.fo
rEach(function (v) {x += v;});return x;}))@shell/collection.js:596
@(shell):1