MongoDB MapReduce Combat <6>

Source: Internet
Author: User
Tags mongodb
OK, continue to complete the second demand, to find the number of records in a day statistics, directly run the "Combat 4" prepared MapReduce, the exception is not a number Nan, through the analysis of the results, found the reason, the reason appears in the first MapReduce, the evidence:
As can be seen in the above image, the times are nested, which leads to an exception in the operation of the problem, need to modify the first mapreduce in the reduce, increase the judgment of the nesting
function Reduce (key, values) {
	var ret={rfid:key};
	var times = new Array ();
	for (var i = 0;i < values.length;i++) {
		if (values[i].times) {Times
			= Times.concat (values[i].times);
		} else{
			Times.push (Values[i]);
		}
	}
	Ret.times = times;
	return ret;
}
Rerun the first MapReduce, then run the second requirement MapReduce, without any modification, to produce the result
From the results, the record in 1 days is 41 times, 42 times in 2 days ...
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.