mongodb의mapreduce 그룹 통계 수량 실현

2109 단어 mapreducemongodb
 :test

db.runCommand(
 { mapreduce : "test",
    map : function() {
					  var nameKey = this.name;
					  kws.forEach(function(kw){
					  var key = kw.key;
						if(nameKey.indexOf(key) == 0){
							nameKey = nameKey.substring(key.length, nameKey.length); 
						}
					  });
                      var key = nameKey;
                      var value = {
                                    count: 1
                                   };

                      emit( key, value );
                  },
    reduce : function(key, values) {

					var reducedObject = {
										  name: key,
										  count:0
										};

					values.forEach( function(value) {
										  reducedObject.name = reducedObject.name;
										  reducedObject.count += value.count;
									}
								  );
					return reducedObject;
				 },
	scope:{kws:[{key:"xm: "},{key:"xm:"}]},
	out: { reduce: "test_group" },
	verbose:true
 }
);

travel_forum
 :title

db.runCommand(
 { mapreduce : "travel_forum",
    map : function() {
                      var titleKey = this.title;
					  kws.forEach(function(kw){
						var key = kw.key;
						if(titleKey.indexOf(key) == 0){
							titleKey = titleKey.substring(key.length, titleKey.length); 
						}
					  });
                      var key = titleKey;
                      var value = 1;
                      emit( key, value );
                  },
    reduce : function(key, values) {

					var count = 0;
					values.forEach( function(value) {
										  count += value;
									}
								  );
					return count;
				 },
	scope:{kws:[{key:" : "},{key:" :"}]},
	out: { reduce: "travel_forum_group" },
	verbose:true
 }
);

좋은 웹페이지 즐겨찾기