ここで何が間違っているのか理解できません。私はpymongoを使用しており、次のmap / reduceコードを使用しています(ドキュメントのすべての属性に直接アクセスできます。つまり、ここに関連する埋め込み部分はありません。
(ファイル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.htmlpymongo2.0.1 ドキュメントのMapReduceの例
コードを実行したときに取得する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コードを見ると、3番目のパラメーター(pymongo 2.0.1のドキュメントによると「out」)は「myresult」であり、これは確かに文字列です。
ここでpymongoは何を不平を言っていますか?Javascriptは構文的に正しいです(私は思います)。現在、reduceは何も実行しないことを知っていますが、これによってコマンドサーバーサイドのコンパイルが妨げられることはありません。