MongoDB MapReduce Combat <3>

Source: Internet
Author: User
Tags mongodb
The final processing results are stored in the "ttt_date_out" table and the next mapreduce is written, and the expected result is the average record generation time Map for all records:
function Map () {
	var count_time = 0;
	var arv_time = 0;
	var times = this.value.times;
	if (times) {
		if (Times.length > 1) {for
			(var i = 0;i < times.length;i++) {
				if (i! = times.length-1) {
					Co Unt_time + = Times[i]-times[i+1];}}
		}
		Arv_time = count_time/(times.length-1);
		Emit (
			' result ', 
			arv_time
		); 
	}
}
Reduce:
function Reduce (key, values) {
	var ret={msg:key};
	var count_times = 0;
	for (var i = 0;i < values.length;i++) {
		count_times + = Values[i];
	}
	Ret.arv_time = count_times/values.length;
	return ret;
}
Finalize: (not in the previous MapReduce, where the main role is to process the results again)
function Finalize (key, reduced) {
	//turn to seconds 
	var second = parsefloat (reduced)/1000;
    Turn minute
	var minute = parseint (SECOND/60);
	Remaining seconds
	var s = second%;
	Turn hours
	var hour = parseint (MINUTE/60);
	Remaining points
	var m = minute%;
	The day after
	var day = parseint (hour/24);
	Remaining hours
	var h = hour%;
    Return day + "days" + H + "hour" + M + "minute" + S + "second";
}
Configure in & Out
Final result
Summary: After a day of efforts to complete the expected goal, tomorrow continue to understand, the final operation of the actual log table to see the effect. Maprecude's programming language is JavaScript, just beginning with the command line, writing and reading too much trouble, finally although the use of Mongovue, but debugging is very difficult, no debug. Find a lot of information also no concrete good method, tragedy.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.