public function testGlobalScope() { $map_reduce = new MongoMapReduce($this->map, $this->reduce); $global_value = 'this is global value!'; $scope = array('global_value' => $global_value); $finalize = <<<FINALIZE \t\t\tfunction finalize(k, v)\t{ \t\t\t\treturn {count: v.count, global: global_value}; \t\t\t} \t\t FINALIZE; $map_reduce->setScope($scope); $map_reduce->setFinalize($finalize); $response = $map_reduce->invoke($this->mongoDB, $this->collectionName); foreach ($response->getResultSet() as $cursor) { $this->assertEquals($global_value, $cursor["value"]["global"]); } }
\t\tthis.tags.forEach(function(x) { emit(x, {count: 1}); }); \t} MAP; $reduce = <<<REDUCE \tfunction(k, v) { var total = 0; for (var i = 0; i < v.length; i++) { total += v[i].count; } return {count: total}; } REDUCE; $map_reduce = new MongoMapReduce($map, $reduce); $collection_name = "animal_tags"; $response = $map_reduce->invoke($mongodb, $collection_name); if ($response->valid()) { echo "Total Execution Time: {$response->getTotalExecutionTime()} Milli Seconds\n"; $count_data = $response->getCountsData(); echo "Count Data\n"; foreach ($count_data as $key => $value) { echo "{$key}: {$value}\n"; } echo "********************\n"; foreach ($response->getResultSet() as $tag) { echo "{$tag["_id"]}\n"; echo "Count: {$tag["value"]["count"]}\n"; echo "****************\n"; } }
public function testShouldReturnMonggoMapReduceResponseObjectAfterUsingInvokeMethod() { $map_reduce = new MongoMapReduce($this->map, $this->reduce); $this->assertTrue($map_reduce->invoke($this->mongoDB, "animal_tags") instanceof MongoMapReduceResponse); }
/** * invoke MapReduce Operation * @param MongoMapReduce $mapReduce * @return MongoMapReduceResponse */ public function mapReduce(MongoMapReduce $mapReduce) { return $mapReduce->invoke($this->mongodb, $this->collectionName); }