`

Map/reduce

阅读更多
db.things.find()
{ "_id" : 1, "tags" : [ "dog", "cat" ] }
{ "_id" : 2, "tags" : [ "cat" ] }
{ "_id" : 3, "tags" : [ "mouse", "cat", "dog" ] }



m = function () {
   this.tags.forEach(function (z) {
   //统计前过滤
   if(z == 'dog'){
     emit(z, {count:1});
   }
    });
  }

f=function (key, values) {
    var result = {count:0};
    values.forEach(function (value) {result.count += value.count;});
    return result;
}


m = function () {
  emit(actionType, {count:1});
}

f=function (key, values) {
    var result = {count:0};
    values.forEach(function (value) {result.count += value.count;});
    return result;
}

res = db.things.mapReduce(m, f, {out: {replace: "test_result"}});




http://www.faithbee.com/?p=180

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics