Plan to use MongoDB MapReduce before you must know!!!

Source: Internet
Author: User

MapReduce is actually batch processing of data, every 100 times reduce processing, so to reduce the data if it is 101, it will be divided into 2 times.

The problem is that in reduce if you initialize var count = 0; in the loop count + +, the last output is 1???

The way to avoid this is to put the data in the returned value, which is reused when the loop enters reduce. In the loop count + = Value.count will be able to add before all 100!!!

And if there is only one piece of data, then it will not enter reduce and will return directly.

Here is a concrete example:

            String map = @ "            function () {                var view = this;                Emit (View.activity, {pv:1});            }" ;             = @ "                    function (key, values) {                var result = {pv:0};                Values.foreach (function (value) {                    RESULT.PV + =  value.pv;                });                return result;            }" ;             = @ "            function (key, value) {                return value;            }";

Plan to use MongoDB MapReduce before you must know!!!

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.