【问题标题】:MongoJS runcommand for mapreduce returning errorMongoJS runco​​mmand for mapreduce 返回错误
【发布时间】:2014-01-09 03:10:10
【问题描述】:

我可以在 NodeJS 中使用 MongoJS 运行简单的 {ping:1} 命令,但是当我尝试运行 mapreduce 命令时收到错误消息。我已经用谷歌搜索了错误的废话,似乎无法在任何地方找到解决方案。

成功的命令

db.runCommand({ping:1}, function(err, res){
    if(!err && res.ok){
        console.log("working")
    }
});

命令失败

db.runCommand({
    mapreduce: "videos",
    map: map,
    reduce: reduce,
    out: "tags"
},function(err, res){
    if(!err && res.ok){
        console.log("working")
    }
});

收到错误

{ errmsg: 'exception: not code', code: 10062, ok: 0 }

这里是 mapFn 和 ReduceFn

var map = function() {
    if (!this.tags) {
        return;
    }

    for (index in this.tags) {
        emit(this.tags[index], 1);
    }
};

var reduce = function(previous, current) {
    var count = 0;

    for (index in current) {
        count += current[index];
    }

    return count;
};

这个例子直接来自MongoDB cookbook

【问题讨论】:

    标签: node.js mongodb mongojs


    【解决方案1】:

    没有查出到底是什么错误,但确实在另一个SO post 中找到了如何在 MongoJS 中使用 mapReduce

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-13
      • 2013-07-03
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多