0

我正在测试 mapreduce 函数,但我有意外的行为:

我用这个简单的 for 循环填充了我的集合:

for (i=0; i<10000; i++) {db.coll.insert({'a':1,'b':2})}

所以我想计算具有相同'a'值的文档(这是一个测试:-))我的地图功能是

map = "function() {  emit(this.a,this.b);}"

和减少是:

reduce = "function (key,values) {return values.length;}"

调用 db.coll.mapReduce(map, reduce, {out:{inline:1}})

预期值为 10000 个具有相同“a”的文档,可以吗?

但结果是:

db.coll.mapReduce(map, reduce, {out:{inline:1}})
{
    "results" : [
            {
                    "_id" : 1,
                    "value" : 101
            }
    ],
    "timeMillis" : 892,
    "counts" : {
            "input" : 10000,
            "emit" : 10000,
            "reduce" : 100,
            "output" : 1
    },
    "ok" : 1,
}

问题出在哪里???为什么值为 101?减少结果中的计数是什么意思?帮我!提前致谢!!!

4

1 回答 1

0

这个结果是非常值得期待的,因为你的 reduce 函数实际上并没有做任何归约。

在这里查看一些基本的 map-reduce 示例,看看 reduce 函数实际上在做什么。它以某种方式组合了每个唯一键的值。你的 reduce 函数没有这样做。

于 2013-04-28T00:25:30.907 回答