2014-01-08 22 views
0

我能够在NodeJS中使用MongoJS运行简单的{ping:1}命令,但是当我尝试运行mapreduce命令时收到错误。我已经从错误中搜索了垃圾,似乎无法在任何地方找到解决方案。MongoJS针对mapreduce的runco​​mmand返回错误

成功命令

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

回答

0

没有找到确切的错误是什么,但确实找到了如何在另一个地方使用mapReduce和MongoJS SO post