Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 43 lines (33 sloc) 0.798 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<?php

require_once "_include.php";

$mongodb = mongodb_fixture();

class AnimalTag extends XMongoCollection {

const COLLECTION_NAME = "animal_tags";

public function __construct(MongoDB $mongoDB) {
$this->collectionName = self::COLLECTION_NAME;
parent::__construct($mongoDB, $this->collectionName);
}
}

$animal_tags = new AnimalTag($mongodb);

$map = <<<MAP
function() {
this.tags.forEach(
function(x) {
emit(x, 1);
}
);
}
MAP;

$reduce = <<<REDUCE
function(key, values) {
return {count: values.length };
}
REDUCE;

$response = $animal_tags->mapReduce(new MongoMapReduce($map, $reduce));
if ($response->valid()) {
foreach ($response->getResultSet() as $tag) {
echo "{$tag["_id"]}\n";
echo "Count: {$tag["value"]["count"]}\n";
echo "****************\n";
}
}
Something went wrong with that request. Please try again.