Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

  $mapFunc = <<<EOT
      function() {
        if (!this.summary) {
          return;
        }
        var summary = this.summary;
        if (summary.type || summary.sum) {
        var index = summary.type + '-' + summary.business;
        var data = {
          type: summary.type,
          business: summary.business,
          sum: summary.sum
        };
        emit(index, data);
      }
    }

EOT;

$map = new MongoCode($mapFunc);
$reduceFunc = <<<EOT
  function(k, list) {
    var result = {type:0, business:0, sum: 0};
    for (var b in list) {
    var item = list[b];
      result.type = item.type;
      result.business = item.business;
      result.sum += item.sum;
    }
    return result;
  }

EOT;

$reduce = new MongoCode($reduceFunc);
$params = array(
  "mapreduce" => 'logs',
  "map" => $map,
  "reduce" => $reduce,
  "query" => null,
  "out" => '_ex'
);
$mongo = $this->Log->getDataSource();
$results = $mongo->mapReduce($params);

比如我上面的代码是对logs集合进行统计,还有一个extend_logs集合,字段都是一样的,也需要如上统计方法,用mongodb的mapreduce方法统计数据可以同时对两个表进行相应的操作么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...