PHP MapReduce Mongodb返回所有地图结果以及缩小的集合?

时间:2014-10-02 16:36:56

标签: php mongodb mapreduce

我想知道每个'whoisPreset'有多少'域名',

例如: 542b151053980df766000000:10 542b151053980df766000002:3

等。

简化文件

> db.Domain.findOne()
{
    "_id" : ObjectId("542b152653980d2467000000"),
    "whoisPreset" : ObjectId("542b151053980df766000000"),
    "whoisPresetUpdated":false
}

php中的MapReduce

        $map = new MongoCode("function() { emit(this.whoisPreset,1); }");

        $reduce = new MongoCode("function(k, vals) { ".
            "var sum = 0;".
            "for (var i in vals) {".
            "sum += vals[i];".
            "}".
            "return sum; }");

        $mapReduce = $this->Couch()->command(
            [
            "mapreduce" => 'Domain',
            "map" => $map,
            "reduce" => $reduce,
            "query" =>
                [
                    'whoisPreset'=>['$ne'=>null,'$exists'=>true],
                    '$or'=>[
                        ["whoisPresetUpdated"=>['$exists'=>false]],
                        ["whoisPresetUpdated" => false],
                        ["whoisPresetUpdated"=>null]
                    ]
                ],
            "out" => ["merge" => "whoisPresetCounts"]
        ]);

        $counts = $this->Couch()->selectCollection($mapReduce['result'])->find();


        foreach ($counts as $tupple) {
            print_r($tupple);
        }

然后在结果中,我似乎得到了每个省略的输出,以及减少的结果

Array
(
    [_id] => MongoId Object
        (
            [$id] => 542b152653980d2467000000
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542b1e5d53980d8c67000001
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542b1f0f53980d8b67000000
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542b1f7b53980db967000006
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542b1ff453980d8b67000007
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542c15f853980dc904000001
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542c17ed53980db605000001
        )

    [value] => 
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542c6bf053980d1013000000
        )

    [value] => MongoId Object
        (
            [$id] => 542b151053980df766000000
        )

)
Array
(
    [_id] => 
    [value] => 7
)
Array
(
    [_id] => MongoId Object
        (
            [$id] => 542b151053980df766000000
        )

    [value] => 8
)

同样在底部有一个带有7个计数的null _id,我没有得到..

有8个文件,基本上与那里给出的第一个例子相同..

0 个答案:

没有答案