我無法弄清楚我在這裏做錯了什麼。我使用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 - 或者它可以嗎?