In mongodb, some values ​​in mapReduce are not processed by reduce.
大家讲道理
大家讲道理 2017-05-17 10:04:04
0
1
577

When using mapReduce in mongodb, some values ​​are not processed by reduce, which is very confusing. First code

    db.test.mapReduce(
        function () {
            emit({
                host: this.host,
                os: this.os,
                computed_on_date: this.computed_on_date,
                uid: this.uid
            }, {data: this.os});
        },
        function (key, value) {
            return {result: 1};
        },
        {
            out: "a"
        }
    )

The data that should be output is

        "_id" : {
                "host" : "www.ddc.com",
                "os" : "android",
                "computed_on_date" : "2017-04-19",
                "uid" : "0ae71c7\ne-7da6-9051-ec6c-49dc671b4e3a"
        },
        "value" : {
                "result" : 1
        }

The actual output data is

      "_id" : {
                "host" : "www.ddc.com",
                "os" : "android",
                "computed_on_date" : "2017-04-19",
                "uid" : "0ae71c7\ne-7da6-9051-ec6c-49dc671b4e3a"
        },
        "value" : {
                "data" : "android"
        }

I am very confused. When the key of condition emit is less than 4, it will be displayed normally. If it is more than 3 or query condition is added, reduce processing will not be performed.

Another question is, when mapReduce has a query, should it process the query first or process reduce and then process the query in the result

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
大家讲道理

It is recommended to use aggregation. Compared with MR, aggregation is the first class feature of MongoDB.

For reference.

Love MongoDB! Have fun!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!