2011-09-15 49 views
3

我无法弄清楚我在这里做错了什么。我使用pymongo并具有以下的map/reduce代码(该文件的所有属性都可以直接访问 - 即没有预埋件与此有关:pymongo用户声明:13606:'out'必须是字符串或对象

(文件getTableMap.js):

function() { 
    var tablePoints1 = 0; 
    var tablePoints2 = 0; 
    if (this.pointsTeam1 == this.pointsTeam2) { 
    tablePoints1 = 1; 
    tablePoints2 = 1; 
    } 
    else { 
    if (this.pointsTeam1 > this.pointsTeam2) { 
     tablePoints1 = 3; 
    } 
    else { 
     tablePoints2 = 3; 
    } 
    } 
    emit(this.idTeam1, [tablePoints1, this.pointsTeam1, this.pointsTeam2]); 
    emit(this.idTeam2, [tablePoints2, this.pointsTeam2, this.pointsTeam1]); 
} 

的它调用map_reduce Python代码看起来是这样的:

def getTableOnMatchday(self): 
    m = Code(open('getTableMap.js','r').read()) 
    r = Code("""function(k,values) { 
    var foo = 'foo'; 
    return(foo); 
    }""") 

    result = bl_1.map_reduce(m, r, "myresult") 
    for doc in result.find(): 
    print doc 

对于Python代码我适应直接从文档的简单例子: http://api.mongodb.org/python/current/examples/map_reduce.htmlMap Reduce example from pymongo 2.0.1 documentation

Python的回溯,当我运行代码,我得到的是:

>>> api.getTableOnMatchday() 
    Traceback (most recent call last): 
    pymongo.errors.OperationFailure: command SON([('mapreduce', u'bl1_2011'), 
    ... 
    ... 
    ... 
) failed: db assertion failure 

这并没有确切地告诉我很多,所以我把上详细的日志记录的mongod,发现这个在日志中:

Thu Sep 15 21:04:02 [conn7] User Assertion: 13606:'out' has to be a string 
or an object 

从查看实际生成map_reduce调用的Python代码,第三个参数('out',根据pymongo 2.0.1文档)是'myresult',这当然是一个字符串。

pymongo在这里抱怨什么? Javascript在语法上是正确的(我认为)。我知道reduce现在什么都不做,但是这不应该阻止编译命令serverside - 或者它可以吗?

回答

6

我想我已经找到了答案,通过更多的试验和错误,并通过阅读文档的PHP驱动程序:

result = bl_1.map_reduce(m, r, out="foo") 

实际上,你必须指定OUT =字符串作为第三个参数。

文档中的例子在这里误入歧途导致,因为它说的事:

result = bl_1.map_reduce(m, r, "foo") 
0

MapReduce的输出选项: 预V1.8:如果没有指定出的值,然后将结果被放入临时集合中,其名称将在命令输出中给出(见下文)。否则,您可以为out选项指定集合的​​名称,并将结果放在那里。

v1.8 +:输出选项已更改。 Map-reduce不再生成临时集合(因此,keepTemp已被删除)。

更多的信息可以发现here

相关问题