title: mongoid - mongodb, mapreduce get scope varriable or pass it to output
body: <p>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?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code> 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
  </code></pre>