mongoid - mongodb, mapreduce get scope varriable or pass it to output

半世苍凉 提交于 2019-12-13 04:46:07

问题


In mapreduce I have a scope total_count to calculate something after grouping something. How can I get back the that scope varriable in output?

EDIT:

 map = %Q{
      function() {  
        ttotal_commission += this.commission;
        tuniq_commission += this.commission; // add first if it not goto reduce
        emit({ip: this.ip, campaign_id: this.campaign_id}, {commission: this.commission, abc: this.commission});
      }
    }

    reduce = %Q{
      function(key, values) {  
        tuniq_commission += values[0].commission; // add 1 and substract laster for uniq

        var total_commission = 0;
        values.forEach(function(value) {    
          tuniq_commission -= value.commission;
          total_commission += value.commission;
        });         
        return {};
      }
    }

    final = %Q{
      function(key, reduceVal){
        reduceVal.ttotal_commission = ttotal_commission;
        reduceVal.tuniq_commission = tuniq_commission;  
        return reduceVal;
      }
    }


temp = Transaction.all.limit(45000).map_reduce(map, reduce).scope(ttotal_commission: 0, tuniq_commission: 0).finalize(final).out(inline: true).first

来源:https://stackoverflow.com/questions/27539387/mongoid-mongodb-mapreduce-get-scope-varriable-or-pass-it-to-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!