减少功能的奇怪问题

时间:2016-06-17 12:11:24

标签: mapreduce couchdb couchbase couchbase-view couchdb-futon

我总是减少练习的问题,比如跟随地图和减少,如果我添加更多文档或添加更多字段在地图中发出并减少如下。它会将值返回为[],不确定会发生什么?

                problemNumber : doc.problemNumber,
                UserId: idv,
                event : doc.event
......

地图

function(doc) {
        if(doc.event){
           var idv = null;
                 for (var idu in doc.Data.users){
                   if (doc.eventData.users[idu].userTypeCode == "M"){

                       idv = doc.Data.users[idu].UserId;
            }
                }
            var newDoc = {
                problemNumber : doc.problemNumber,
                UserId: idv,
                event : doc.event

            };
          emit(null, newDoc);
      }
    }

减少

function(keys, values, rereduce) {
    var result = [];
    var closeMap = {};
    for (var i=0; i<values.length; i++){
       var doc = values[i];
       if (doc.event=='CLOSE'){
           closeMap[doc.problemNumber] = 1;
       }
    }
    for (var i=0; i<values.length; i++){
       var doc = values[i];
       if (doc.event=='OPEN'){
           if (closeMap[doc.problemNumber]){
               doc.event = 'CLOSE';
           }
           result.push(doc);
       }
    }
    return result;
}

0 个答案:

没有答案