0

map reduce を使用して、ユーザーのビジネス評価を 1 つのコレクションに集約しようとしています。

mapper = Code("""
              function(){
              var userID = this.user_id;
              var business = this.business_id;
              var rating = this.stars;

              emit(userId, {business_id: business, stars: rating});
              """)

reducer = Code("""
              function(key, values){
              var results = new Object();
              results.values = values;
              return results;

{u'_id': u'--65q1FpAL_UQtVZ2PTGew', u'value': {business: rating}, {business: rating}} を取得することを期待します

しかし、私が得ているのは {u'_id': u'--65q1FpAL_UQtVZ2PTGew', u'value': [u'values':[[u'values':[ u'values': [{business: rating} 、{ビジネス: 評価}...

出力から余分な「値」タグをすべて削除するにはどうすればよいですか?

4

1 に答える 1

0

代わりに集約を使用することを検討しましたか? これは一般に mapReduce よりも効率的であり、アプリケーションにより適しているようです。たとえば、問題に対する集約ソリューションは次のようになります。

db.coll.aggregate({ $group: { _id: "$user_id", 
                    values: { $push: { business_id: "$business_id", 
                                       stars: "$stars" }}}});

その後、結果を新しいコレクションまたはその他の好きなものに保存できます。

于 2013-09-20T14:48:42.853 に答える