Skip to content

Instantly share code, notes, and snippets.

@michaeltwofish
Created February 10, 2012 00:30
Show Gist options
  • Save michaeltwofish/1784787 to your computer and use it in GitHub Desktop.
Save michaeltwofish/1784787 to your computer and use it in GitHub Desktop.
Lithium MongoDB map reduce example
$map = 'function() {
this.forms.forEach(function(form){
form.clusters.forEach(function(cluster){
cluster.items.forEach(function(item){
emit(item, item);
})
})
})
}';
$reduce = 'function (key, values) {
return values;
}';
// Run the command
$items = Test::connection()->connection->command(array(
'mapreduce' => 'tests',
'map' => $map,
'reduce' => $reduce,
'out' => array('inline' => 1)
));
foreach ($items['results'] as $item) {
var_dump($item['value']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment