Skip to content

Instantly share code, notes, and snippets.

@tholder
Created December 23, 2011 12:04
Show Gist options
  • Save tholder/1513997 to your computer and use it in GitHub Desktop.
Save tholder/1513997 to your computer and use it in GitHub Desktop.
Map Reduce - Using Shanty
<?php
$id = new MongoId($contact['custom']['skadoosh_id']);
$mapFunction = new MongoCode("function() { if (this.actor.id == \"$id\") emit(this.verb, 1); }");
$reduceFunction = new MongoCode("function(k,v) { var sum=0; for(var i in v) sum += v[i]; return sum; }");
$verbs = Model_Mongo_Activities::getMongoDb()->command(array(
"mapreduce" => "activities",
"map" => $mapFunction,
"reduce" => $reduceFunction,
"out" => array("inline" => true)));
$this->view->verbs = array();
foreach($verbs["results"] as $verb) {
$this->view->verbs[$verb["_id"]] = $verb['value'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment